本文介绍了MaskedTextBox的多行遮罩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Winforms应用程序中有一个MaskedTextBox.我需要在其上放置多行蒙版,例如:

I have a MaskedTextBox in my Winforms application. I need a multiline mask on it, f.e:

"999999\r\n
 999999\r\n
 999999\r\n
 00/00/0000"

我阅读了 msdn文档,很惊讶地发现没有换行符"之类的东西.

I read the msdn documentation and was suprised to see that there is no "new line"or something like that.

我知道我可以编写自己的用户控件来解决此问题,但是带遮罩的文本框将是一个更简单的解决方案.所以我有2个问题:有没有办法向蒙版添加新行?如果没有,控件为什么支持多行-没用吗?

I know that i can write my own user control to fix this issue, but a masked textbox would be an easier solution.So i have 2 Questions: Is there a way to add a new Line to a mask?If not, why does the Control supports multiline - isnt that useless?

预先感谢

推荐答案

为此,我将创建一个自定义控件,该控件将为每行组合MaskedTextBox集现在,根据需要,可以使用恒定数量的MaskedTextBox一个哑"控件在另一个控件下以及格式字符串的相应属性

For that I would create a custom control that would combine set of MaskedTextBox for each lineNow, depending on the need, either "dumb" control with constant amount of MaskedTextBox one under another and corresponding properties for format strings

public string Format1 {get;set;}
public string Format2 {get;set;}
public string FormatX {get;set;}

或创建一个具有属性"LinesCount"等的智能"版本,当您将其设置为5时,将添加5个MaskedTextBox,左右分别设置锚点(整个控件可伸缩)

Or create a "smart" version, with property "LinesCount" etc, when you set to 5 it would add 5 MaskedTextBox with set anchor to left and right (for the whole control to be stretchable)

然后是属性

public List<string> Formats {get;set;}

每行对应于每个MaskedTextBox

each line would correspond to each MaskedTextBox

其他属性值

public List<X> Values

每行将与每个MaskedTextBox.Value相对应,其中X是我不记得它返回的类型.

each line would correspond to each MaskedTextBox.Value, where X is type I don't remember it returns.

您想要的控件越复杂,越聪明,越有用,您需要放置更多的代码:)但可行

The more complicated and smart and useful control you want the more coding you need to put :) but doable

这篇关于MaskedTextBox的多行遮罩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 02:12