-
December 21st, 2009, 01:13 AM
#1
Int to string as hex
I need to display a int as a sting, but i need it to be displayed in hex. This is what i have so far.
this.tbx_result.Text = Convert.ToString(seed);
*EDIT* I figured this part out, but my next problem is i need to figure out how to only allow hex characters to be entered in to the textbox.
Last edited by KazoWAR; December 21st, 2009 at 03:02 AM.
-
December 21st, 2009, 03:36 AM
#2
Re: Int to string as hex
To only allow hex characters, use the KeyPress event on the textbox e.g.
Code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
bool isHexDigit =
Char.IsDigit(e.KeyChar) ||
(e.KeyChar >= 'a' && e.KeyChar <= 'f') ||
(e.KeyChar >= 'A' && e.KeyChar <= 'F');
// if not a hex digit, don't continue processing the keypress
e.Handled = !isHexDigit;
}
Darwen.
-
December 21st, 2009, 05:01 AM
#3
Re: Int to string as hex
Originally Posted by darwen
To only allow hex characters, use the KeyPress event on the textbox e.g.
Code:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
bool isHexDigit =
Char.IsDigit(e.KeyChar) ||
(e.KeyChar >= 'a' && e.KeyChar <= 'f') ||
(e.KeyChar >= 'A' && e.KeyChar <= 'F');
// if not a hex digit, don't continue processing the keypress
e.Handled = !isHexDigit;
}
Darwen.
Ok, Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|