none
Controlling User Entry RRS feed

  • Question

  • Hi, can someone tell me how to control user entry in C#? I'm migrating a huge legacy app from FoxBase, where I have control over user entry with PICTURE clauses. With them I can limit the number of characters being entered, convert to uppercase automatically as they type, force numeric or alpha input only, all kinds of fun things. I can't seem to find anything similar in C#, but maybe it's just buried somewhere in all that hideous complexity. I can't even find a non-proportional typestyle so that at least the user could see when a textbox was maxed out. Any advice, other than sticking with XBase?
    Wednesday, July 15, 2009 3:01 PM

Answers

  • There is a masked textbox that may provide some of the functionality that you are looking for.

    You could also build your own user control that inherits from Textbox (or MaskedTextBox) and add whatever other functionality you need.

    Consolas is a fixed-width typestyle that you could use if you need one.

    Hope this helps.
    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Proposed as answer by Harry Zhu Wednesday, July 22, 2009 6:25 AM
    • Marked as answer by Harry Zhu Thursday, July 23, 2009 9:35 AM
    Wednesday, July 15, 2009 3:14 PM
  • If its a windows application, you can also handle the key down and keypress events so that those keys are disabled...
    student,UH
    • Proposed as answer by Harry Zhu Wednesday, July 22, 2009 6:25 AM
    • Marked as answer by Harry Zhu Thursday, July 23, 2009 9:35 AM
    Wednesday, July 15, 2009 7:46 PM

All replies

  • There is a masked textbox that may provide some of the functionality that you are looking for.

    You could also build your own user control that inherits from Textbox (or MaskedTextBox) and add whatever other functionality you need.

    Consolas is a fixed-width typestyle that you could use if you need one.

    Hope this helps.
    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    • Proposed as answer by Harry Zhu Wednesday, July 22, 2009 6:25 AM
    • Marked as answer by Harry Zhu Thursday, July 23, 2009 9:35 AM
    Wednesday, July 15, 2009 3:14 PM
  • If its a windows application, you can also handle the key down and keypress events so that those keys are disabled...
    student,UH
    • Proposed as answer by Harry Zhu Wednesday, July 22, 2009 6:25 AM
    • Marked as answer by Harry Zhu Thursday, July 23, 2009 9:35 AM
    Wednesday, July 15, 2009 7:46 PM
  • Thanks DeborahK for the Masked Text Box suggestion, upon further reading it looks like that will do the trick. Unfortunately it appears to be a Windows Forms class and I'm trying hard to work within WPF so as not to become obsolete quite as quickly. But as you said, I can build a user control that does what I want... I was just hoping for a shortcut! And thanks for the tip on the Consolas font... since I first posted, I've gone through all of the supplied fonts and eventually stumbled on "Lucida" as a non-proportional font. Don't know how I missed Consolas, but surprisingly the "OCR" font is proportional... I assumed it stood for Optical Character Recognition and would have bet it had evenly-spaced characters. But Lucida is an elegant font and now with Consolas I have options! Thanks,
    Jim Harris
    Saturday, July 25, 2009 8:07 PM
  • Thank you Vayuu, I put your suggestion to good use and managed to take control of all my numeric data entry points such that only numbers, decimals, and minus signs are allowed. That solves my numerical challenge, and that's a big deal for an accounting application like the one I'm working on. Now if I can just figure out a way to convert characters to uppercase as they enter... I can do anything I want with it once they leave the entry field but not as they type it in.  But I'll figure it out!
    Thanks,
    Jim Harris
     
    Saturday, July 25, 2009 8:35 PM
  • just to give you a hint click on the textbox and view all the properties...

    student,UH
    Monday, July 27, 2009 2:49 PM
  • You may want to post any further WPF question to the WPF forum:

    http://social.msdn.microsoft.com/Forums/en-US/wpf/threads

    Hope this helps.


    www.insteptech.com ; msmvps.com/blogs/deborahk
    We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
    Monday, July 27, 2009 3:41 PM