Reputation: 33
I have developed a windows form application using Bunifu .NET UI Framework.
But I have a problem, I want to set max length of the text box.
Therefore please give me some advice, how can I do it?
Upvotes: 0
Views: 1936
Reputation: 41
Simple way, Assign the MaxLength property on TextChange event of the textbox (Working 100%)
int maxLength=5;
private void textbox1_TextChange(object sender, EventArgs e)
{
textbox1_TextChange.MaxLength = maxLength + txtActivationKey.PlaceholderText.Length;
}
Upvotes: 0
Reputation: 339
You can likewise use the method below:
/// <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...
}
}
}
Upvotes: 1
Reputation: 116
Here is working code - add the code on form load or your constructor like BunifuMetro(yourtextbox); after InitializeComponent(). You can try and switch between the controls by replacing Bunifu.Framework.UI.BunifuMetroTextbox with another textbox; Cheers
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
}
}
}
Upvotes: 0