0

Possible Duplicate:
C# convert integer to hex and back again

I want to make a code with "if" to make me that: We are starting the program and we have one textbox - "textbox1" and one button - "button1". We need to start a cycle that starts to count from 0 and each click on the button1 brings it +1, so for now we have: Start program>click button>cycle starts and we have 1> click again - we have 2 and etc. (this 1,2,3 ...n wont be shown anywhere) After that we need to show the current value of the cycle in this HEX format - "00-00-00-00" in textbox1. So we got: First click will be first moment of cycle, so we have current DEC value "1" and in hex it must be - "00-00-00-01" and here it comes the hottest part(for me ..) when the DEC value=255 in HEX it must be - "00-00-00-FF" and when the cycle(dec value) hits 256 it must be "00-00-01-00" and again the same till the dec value=511 - we will have "00-00-01-FF" and on decvalue=512 we will have "-00-00-02-00".

Thanks in advance for help!

Community
  • 1
  • 1

1 Answers1

1

This code should do what you want:

public int Counter { get; set; }

private void button1_Click(object sender, System.EventArgs e) {
    Counter++;
    textbox1.Text = Counter.ToString("X");
}

But there is no "if" in it... :(

Yannick Blondeau
  • 8,867
  • 7
  • 48
  • 67