我对如何在 Windows 窗体应用程序中显示结果感到困惑。
private void btnBrowse_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
txtFileName.Text = openFileDialog1.FileName;
}
}
private void btn_search_Click(object sender, EventArgs e)
{
var result = File.ReadAllLines(@txtFileName.Text).Select(s => s.Contains(txt_search.Text));
}
我想将搜索结果显示为列表。谁能帮我?
最佳答案
一种简单的方法是只设置一个文本框,该文本框会在搜索完成后更新。
private void richTextBox1_TextChanged(object sender, EventArgs e)
{
richTextBox1.SelectionStart = richTextBox1.Text.Length; //Set the current caret position at the end
richTextBox1.ScrollToCaret(); //Now scroll it automatically
}
private void btnBrowse_Click(object sender, EventArgs e)
{
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
txtFileName.Text = openFileDialog1.FileName;
}
}
private void btn_search_Click(object sender, EventArgs e)
{
var result = File.ReadAllLines(@txtFileName.Text).Select(s => s.Contains(txt_search.Text));
this.richTextBox1.AppendText(result.ToString()); //---> Appends the Text to the Rich Text Box, you may want to change the variable result(i hope its not a collection)
}
关于c# - 在 Windows 应用程序中显示结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31918455/