如何從文本框類創建驗證器或創建新文本框,而不是從工具箱中拖動文本框
private void Form1_Load(object sender, EventArgs e)
{
createTextpass();
// Creating and setting the properties of TextBox1
TextBox textboxUsername = new TextBox();
textboxUsername.Location = new Point(420, 50);
textboxUsername.Size = new Size (300,30);
textboxUsername.Name = "text_user";
this.Controls.Add(textboxUsername);
TextBox textboxPassword = new TextBox();
textboxPassword.Location = new Point(420, 80);
textboxPassword.Size = new Size(300, 30);
textboxPassword.Name = "text_pass";
this.Controls.Add(textboxPassword);
TextBox textboxMail = new TextBox();
textboxMail.Location = new Point(420, 110);
textboxMail.Size = new Size(300, 30);
textboxMail.Name = "text_mail";
this.Controls.Add(textboxMail);
}
uj5u.com熱心網友回復:
添加 texbox 的寬度和高度
uj5u.com熱心網友回復:
如果我正確理解你的問題。您想創建一個文本框并檢查此文本框中是否輸入了有效文本。例如,以下代碼可用于textboxUsername:
public TextBox textboxUsername;
private void Form1_Load(object sender, EventArgs e)
{
createTextpass();
// Creating and setting the properties of TextBox1
textboxUsername = new TextBox();
textboxUsername.Location = new Point(420, 50);
textboxUsername.Size = new Size(300, 30);
textboxUsername.Name = "text_user";
this.Controls.Add(textboxUsername);
textboxUsername.TextChanged = new EventHandler(usernameTextbox_TextChanged);
....
}
//If textboxUsername contains the # character, an alarm will be displayed
protected void usernameTextbox_TextChanged(object sender, EventArgs e)
{
if (textboxUsername.Text.Contains('#'))
MessageBox.Show("inavlid char in userName");
}
uj5u.com熱心網友回復:
首先創建這個函式:
private void Calltextbox()
{
TextBox txtPass = new TextBox();
txtPass.Location = new Point(80, 60);
txtPass.AutoSize = true;
txtPass.Validating = new CancelEventHandler(txtPass_Validating);
txtPass.Name = "txtPass";
Controls.Add(txtPass);
}
完成,未找到名為 txtPass 的 txtPass_Validating 函式
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/521177.html
標籤:C#表格验证
上一篇:Java匯入陳述句中的錯誤“無法決議匯入javax.validation.constraints.NotNull和NotEmpty”
