如何在整个 .Net winforms 应用程序中将输入限制为有限的字符集。 (vb.net/c#)
我工作的公司拥有极其陈旧的数据库系统和许多遗留应用程序,当遇到非 ASCII 字符时,它们会抛出硬错误。
自从他们意识到这些应用程序需要消失后,他们开始将后端包装在 vb.net WinForms 应用程序中,在包装这些旧系统 1.5 年后,他们发现了这个错误。
他们雇用我来解决这个问题。 :(
在许多情况下,UI 是使用 DevExpress 等第三方的数据绑定和 FormView 式解决方案构建的。因此,分解 UI 并使用类似于以下的中间实用函数重新组合它们需要大量工作:
TextBox.Text = Sanitize(dataObject.Value);
and
dataObject.Value = Sanitize(TextBox.Text);
我正在寻找一种方法来破解应用程序 CultureInfo(或其他一些属性),以便所有文本框本身只处理 ASCII,类似于许多网络浏览器似乎表现出的行为
另请注意:许多文本。输入来自 dev express,因此即使正在使用的文本框也被包装起来。
是否有办法附加到 Forms 的 ControlAdded 事件并将控件设置为仅处理 ASCII 或 utf-8/utf-7
?如果我没有采取一些可怕的黑客手段的话,我将花费两年的时间来修复所有这些应用程序。
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 behavior 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以递归地处理每个表单的
ControlAdded
来修改每个 TextBox。然后,处理
KeyPress
事件并设置e.Handled = true
(如果您不喜欢该角色)。对于 DevExpress 编辑器,您需要处理
TextEdit
或TextBoxMaskBox
,但不能同时处理两者。You can recursively handle
ControlAdded
for each form to modify every TextBox.Then, handle the
KeyPress
event and sete.Handled = true
if you don't like the character.For DevExpress editors, you'll need to handle the
TextEdit
or theTextBoxMaskBox
, but not both.