开发者

How do I restrict input to a limited character set across an entire .Net winforms application. (vb.net/c#)

开发者 https://www.devze.com 2023-01-30 23:24 出处:网络
The company I work for has ridiculously old database systems and many legacy apps that throw hard errors when they encounter non-ascii characters.

The company I work for has ridiculously old database systems and many legacy apps that throw hard errors when they encounter non-ascii characters.

Since they realized those apps need to go they started wrapping the back end in vb.net WinForms apps, and after 1.5 years of wrapping these old systems they discovered this bug.

They have hired me to fix the problem. :(

In many cases UIs were built using databinding and FormView-esque solutions from third parties like DevExpress. As a result, it would take a lot of work to decompose the UIs and and recompose them with some middle utility function similar to the following:

TextBox.Text = Sanitize(dataObject.Value);
and
dataObject.Value = Sanitize(TextBox.Text);

I am looking for a way that I could hack the Applications CultureInfo (or some other property) so that all the text boxes natively only handle ASCII, similar to the behavi开发者_如何转开发or many web browsers seem to exhibit.

Also as a note: many of the text inputs come from dev express so even the textboxes being used are wrapped up.

Is there a way perhaps to attach to the Forms' ControlAdded event and set the control to only handle ASCII, or utf-8/utf-7?

Someone out there has to have encountered this. It will take me 2 years to fix all of these apps if there isn't some horrendous hack I can put in place.


You can recursively handle ControlAdded for each form to modify every TextBox.

Then, handle the KeyPress event and set e.Handled = true if you don't like the character.

For DevExpress editors, you'll need to handle the TextEdit or the TextBoxMaskBox, but not both.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号