【发布时间】:2015-04-22 20:57:06
【问题描述】:
我有一个列表视图并创建了一个文本框来搜索该列表中的项目! 搜索一切正常! 但问题是我希望我的搜索框是这样的: 起初 Searchbox.Text="Search ..." 如果用户开始在该搜索框中输入,则更改为该关键字! else(if) searchbox 有空 Searchbox.Text 再次更改为“Search ...”! 也许它有点复杂!但我试了1-2个小时!来不及了! 我用过定时器、checkboxchange 事件、布尔值、...!但做不到! :( 请帮忙! *我的搜索框名称是 textbox1。 我测试的一些代码:
private void textBox1_TextChanged(object sender, EventArgs e)
{
string str = textBox1.Text;
/*
if (!keywordentered_bool)
{
textBox1.Text = "";
}
*/
if (str != "")
{
//Doing Search operations!
search_bool = true;
}
else
{//Doing Search operations!
search_bool = true;
// keywordentered_checkbox.Checked = true;
Searchtextbox_Timer.Interval = 100;
Searchtextbox_Timer.Enabled = true;
Searchtextbox_Timer.Tick += Searchtextbox_Timer_Tick;
//textBox2.Visible = false;
}
}
else
{
if (search_bool)
{
listView1.Items.Clear();
label1.Visible = false;
listView1.Items.AddRange(Originalplaylist_list.ToArray());
if (!search_bool)
{
listView1.Items[MusicLogindex_list[MusicLogindex_list.Count - 1]].ForeColor = Color.Cyan;
}
else if (search_bool)
{//Doing Search operations
search_bool = false;
Searchtextbox_Timer.Interval = 100;
Searchtextbox_Timer.Enabled = true;
Searchtextbox_Timer.Tick += Searchtextbox_Timer_Tick;
//textBox2.Visible = true;
// keywordentered_checkbox.Checked = false;
}
}
void Searchtextbox_Timer_Tick(object sender, EventArgs e)
{
if (!search_bool)
{
textBox2.Visible = true;
textBox2.Location = textBox1.Location;
//textBox1.Text = "Search ...";
//textBox1.ForeColor = Color.Gray;
//textBox1.Font = new Font(textBox1.Font, FontStyle.Italic);
}
else
{
textBox2.Visible = false;
// textBox1.Text = "";
// textBox1.ForeColor = Color.Black;
// textBox1.Font = new Font(textBox1.Font, FontStyle.Regular);
}
Searchtextbox_Timer.Enabled = false;
//throw new NotImplementedException();
}
【问题讨论】:
-
Winforms 还是 Asp.net 网络表单?
-
@FrebinFrancis 我认为您引用的链接是我正在寻找的,但不幸的是演示下载链接不起作用! ://
-
@ACE 你用源码链接试试?
-
我下载了,但还没有测试,因为它只是一个类!
标签: c# search textbox user-input