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

时间:2018-03-22 09:22:17

标签: bunifu

我使用Bunifu .NET UI Framework开发了Windows窗体应用程序。但我有一个问题。实际上,我想设置文本框的最大长度。但是怎么样?因此,请给我一些建议。

3 个答案:

答案 0 :(得分:0)

这是工作代码 - 在表单加载或构造函数上添加代码,如 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
                }

            }

        }

答案 1 :(得分:0)

您也可以使用以下方法:

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

答案 2 :(得分:0)

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

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