CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2009
    Posts
    29

    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.

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Nov 2009
    Posts
    29

    Re: Int to string as hex

    Quote Originally Posted by darwen View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured