c# TextChanged不能启动(非ASP.net)桌面应用程序
本文关键字:net 桌面 应用程序 ASP TextChanged 不能 启动 | 更新日期: 2023-09-27 18:14:04
我是c#的新手,一直在尝试学习如何使用文本更改,以便用户不必手动点击按钮。但我可以让我的应用程序工作与textChanged事件。我已经创建了一个测试程序,看看它是否有效,是的,它确实有效。这里是非工作代码,我需要帮助,如果你需要更多的请让我知道。
代码形式:
private void custFNameTxt_TextChanged(object sender, EventArgs e)
{
searchFirstName(custFNameTxt, customers);//search first name make searched list
Console.Write("working!!!!!!!!!!!!!!!!!!!!!!!"); // for testing
}
当我添加event:
时,代码被添加到设计器中。//
// custFNameTxt
//
this.custFNameTxt.Location = new System.Drawing.Point(98, 45);
this.custFNameTxt.MaxLength = 12;
this.custFNameTxt.Name = "custFNameTxt";
this.custFNameTxt.Size = new System.Drawing.Size(171, 20);
this.custFNameTxt.TabIndex = 1;
this.custFNameTxt.TextChanged += new System.EventHandler(this.custFNameTxt_TextChanged);
我已经尝试将处理程序添加到加载表单(这没有使它工作):
private void Form1_Load(object sender, EventArgs e)//when form loads do this
{
//set unsername field to be selected on load
usernameTxt.Focus();
custFNameTxt.TextChanged += new EventHandler(custFNameTxt_TextChanged);
}
这是它调用的方法,以防问题是与它有关,而不是事件调用:
private void searchFirstName<T>(Control textBox, List<T> list)//method to search customers by first name
{
if (list.GetType() == typeof(List<Customer>))
{
searchForThis = (textBox as TextBox).Text.ToUpper().Trim().ToString();
for (int i = 0; i < customers.Count -1; i++)
{
searchThis = customers[i].F_name.ToUpper();
if(searchThis.Substring(0, searchForThis.Length) == searchForThis)
{
searched.Add(customers[i]);
}
}//end for loop
}//end if type of customer
我太快了,太寻求帮助,看起来我有一堆其他需要的代码在我的按钮推,需要在文本更改工作正确。谢谢大家的帮助,我一直想不出问题是什么,直到有人给我一些建议。
if (!string.IsNullOrEmpty(custFNameTxt.Text) && string.IsNullOrEmpty(custIdTxt.Text) ||
!string.IsNullOrEmpty(custLNameTxt.Text) && !string.IsNullOrEmpty(custFNameTxt.Text) ||
string.IsNullOrEmpty(custLNameTxt.Text) && !string.IsNullOrEmpty(custFNameTxt.Text))
{
searchFirstName(custFNameTxt, customers);//search first name make searched list
custSearchList.Clear();
foreach (Customer custs in searched)
{
altRowColor(searched, custSearchList);//iterate throught list alt row color
}
altCust = 0;//reset altCust to avoid errors
if (!string.IsNullOrEmpty(custFNameTxt.Text) && !string.IsNullOrEmpty(custLNameTxt.Text))//Narrow down the search
{
narrowByLast();//narrow method
custSearchList.Clear();//clear text
foreach (Customer custs in searched)
{
altRowColor(searched, custSearchList);//iterate throught list alt row color
}
altCust = 0;//reset altCust to avoid errors
}
}