【发布时间】:2017-10-26 09:34:43
【问题描述】:
我正在尝试创建一个在列表框中搜索名称的应用程序。 基本上,我有 2 个 .txt 文件(BoyNames、GirlNames)一个文件包含一组男孩名字和另一个女孩名字。我设法将男孩的名字显示到 boyNameListBox 和女孩的名字显示到 girlNameListBox。请参考附上的图片。我正在尝试添加一个功能,如果用户输入男孩的名字(在男孩文本框中)并且名字在列表框中列出,应用程序将返回一个显示“流行”的消息框;如果未列出该名称,该应用程序将显示一个消息框,显示不受欢迎。我希望包括相同的搜索功能,但女孩的名字。我对编程很陌生,非常感谢您的帮助。提前致谢!!
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void readButton_Click(object sender, EventArgs e)
{
{
//local variables
string line1;
//Catch Boy Names File
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\Harra\Documents\Visual Studio 2017\Projects\Name Search\BoyNames.txt");
//display items BoyNames file to Listbox
while ((line1 = file.ReadLine()) != null)
boyNameListbox.Items.Add(line1);
}
{
//local variales
string line2;
//Catch Girl Names File
System.IO.StreamReader file = new System.IO.StreamReader(@"C:\Users\Harra\Documents\Visual Studio 2017\Projects\Name Search\GirlNames.txt");
//display items GirlNames file to Listbox
while ((line2 = file.ReadLine()) != null)
girlNameListbox.Items.Add(line2);
}
}
private void boyButton_Click(object sender, EventArgs e)
{
}
private void girlButton_Click(object sender, EventArgs e)
{
}
}
【问题讨论】:
-
做一个简单的谷歌搜索..也编辑你的代码并正确格式化你有
{ }使用不当..这并不难 -
感谢您的回复,是的,我尝试过 google 搜索,但由于我的技能水平有限,我无法理解。你能帮忙吗?
-
抽出时间去谷歌搜索一下
C# Basics Tutorials for beginners是我要开始的地方。大量免费的在线资源/教程/视频
标签: c# search textbox listbox streamwriter