Posted on 2006-04-29
Last Modified: 2012-08-13
Dear Experts

i am asking about a mask that take only HEX.
and how to make this MaskedTextBox Upper Case
thank you
Question by:RamzyEbeid
    LVL 7

    Accepted Solution

    There is no masking character for HEX
    For uppercase, put a > at the start of the mask.

    For more info in VS, visit ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.NETDEVFX.v20.en/CPref17/html/P_System_Windows_Forms_MaskedTextBox_Mask.htm

    You can accomplish your requirement using either a MaskedTextBox or a standard TextBox by handling the KeyPress events, the method you need is:

        private void maskedTextBox1_KeyPress(object sender, KeyPressEventArgs e) {
          String key = e.KeyChar.ToString().ToUpper();
          char[] permittedKeys = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
          if ( key.IndexOfAny(permittedKeys) == -1 ) {
            e.Handled = true;
          } else {
            e.KeyChar = key[0];

    Please post back if you require further explanation - I've tested this in Visual Studio 2005 and it works fine.

    Assisted Solution

    However, while that would work, other text could potentially be pasted into the textbox.
    Better would be to put code in TextBox1_Change (or whatever it is) that checks each character and removes any that are not valid hex characters.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now