0

Dear All We had developed a hr application(winform) which consist of almost 98 forms .And its in testing in our organisation . But the problem now is the management wants all the data inputs to be in UPPERCASE .we had not set any character casing in any of our controls and now its almost very hazardous to change the character casing to all controls

Can anyone suggest any idea to do restrict the input to uppercase only ?.I had tried some thing at the Program.cs file.but it seems not working

Also tried to overide textbox.textchanged event it seems to be a foolish idea any more ideas please considering us as new bie in development

Sreenath Ganga
  • 696
  • 4
  • 19
  • 48

2 Answers2

2

Although this is a weird requirement, you could use LINQ to "upper-text" all TextBox-Controls:

var allTxt = from form in Application.OpenForms.Cast<Form>()
             from txt in form.Controls.OfType<TextBoxBase>()
             select txt;
foreach (var txt in allTxt)
    txt.Text = txt.Text.ToUpper();

Application.OpenForms returns all open forms owned by the application and TextBoxBase is the base class of text-controls(TextBox, RichTextBox). Enumerable.OfType filters for TextBoxBase.

Note that this doesn't search recursively for controls. Only the top control-container is searched currently. If you need a recursive search implement something like this.

Community
  • 1
  • 1
Tim Schmelter
  • 450,073
  • 74
  • 686
  • 939
0

Have a look at the KeyPreview event, it may allow you to control all input for the app, regardless of where the focus is.

I would say that by far the best solution would be to replace all the textboxes with your own implementation of the textbox - making changes like this more simple, but if that's not practical, KeyPreview should work.

Paul Michaels
  • 16,185
  • 43
  • 146
  • 269