c# - 在 Windows 应用程序中显示结果

标签 c# winforms

我对如何在 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/

相关文章:

c# - Entity Framework : An error occurred while updating the entries

c# - 如何正确序列化和反序列化Json中的对象列表?

java - 为什么ArrayList创建时元素数组为空,而HashSet创建时表为空?

c# - 控件在 Windows 窗体上相交

c# - 如何从另一种形式调用函数

c# - 如何告诉 Nest ElasticSearch 只使用 InterfaceProperties

扩展方法中的 C# out 参数

c# - 如何添加多个文本框数字,并将总和存储为 double 变量

c# - 动态添加控件到用户控件

c# - Winforms 将枚举绑定(bind)到单选按钮