我使用Bunifu .NET UI框架开发了一个windows表单应用程序。
但是我有个问题,我想设置文本框的最大长度。
所以请给我一些建议,我该怎么做呢?
发布于 2018-03-23 07:55:47
您也可以使用以下方法:
/// <summary>
/// Sets the maximum length of text in Bunifu MetroTextBox.
/// </summary>
/// <param name="metroTextbox">The Bunifu MetroTextbox control.</param>
/// <param name="maximumLength">The maximum length of text to edit.</param>
private void SetMaximumLength(Bunifu.Framework.UI.BunifuMetroTextbox metroTextbox, int maximumLength)
{
foreach (Control ctl in metroTextbox.Controls)
{
if (ctl.GetType() == typeof(TextBox))
{
var txt = (TextBox)ctl;
txt.MaxLength = maximumLength;
// Set other properties & events here...
}
}
}发布于 2018-03-23 07:33:43
下面是工作代码--在表单加载上添加代码,或者在InitializeComponent()之后添加构造函数,比如InitializeComponent()。您可以尝试通过用另一个文本框替换Bunifu.Framework.UI.BunifuMetroTextbox来在控件之间切换;
private void BunifuMetro(Bunifu.Framework.UI.BunifuMetroTextbox metroTextbox)
{
foreach (var ctl in metroTextbox.Controls)
{
if (ctl.GetType() == typeof(TextBox))
{
var txt = (TextBox)ctl;
txt.MaxLength = 5;
// set other properties & events here
}
}
}发布于 2020-06-20 17:34:14
简单的方法,在文本框的MaxLength事件上分配TextChange属性(工作时间为100%)
int maxLength=5;
private void textbox1_TextChange(object sender, EventArgs e)
{
textbox1_TextChange.MaxLength = maxLength + txtActivationKey.PlaceholderText.Length;
}https://stackoverflow.com/questions/49424788
复制相似问题