如何设置文本框"Bunifu .NET UI Framework"最大长度?



我开发了一个使用Bunifu .NET UI Framework的Windows表单应用程序。

但是我有一个问题,我想设置文本框的最大长度。

因此,请给我一些建议,我该怎么做?

您也可以使用以下方法:

/// <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...
        }
    }
}

这是工作代码 - 在表单加载或构造函数(如 BunifuMetro(yourtextbox((中添加代码;在 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
                }
            }
        }

简单的方法,在文本框的 TextChange 事件上分配 MaxLength 属性(工作 100%(

    int maxLength=5;
    private void textbox1_TextChange(object sender, EventArgs e)
    {
        textbox1_TextChange.MaxLength = maxLength + txtActivationKey.PlaceholderText.Length;
    }

最新更新