得到2并显示数据的用户输入在Form1在C# [英] get user input in form2 and display data in form1 in c#

查看:114
本文介绍了得到2并显示数据的用户输入在Form1在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


,还有搜索按钮。点击时,会弹出第二种形式(右图)。

in the left picture, there is search button. when click, it will popup the second form (right picture).

,该数据将出现在Form1上。如何通过字由用户在窗口2输入到Form1?

when entering the keyword on search form (form2), the data will appear at the form1. how to pass the word enter by user in form2 to form1?

这是在Form1的代码。

this is the code in form1.

private void button5_Click(object sender, EventArgs e)
    {            
        Form2 form2 = new Form2();
        form2.ShowDialog();   //open form2-search form  

        //kene get data input dr form2
        XmlDocument xml = new XmlDocument();            
        xml.Load("C:\\Users\\HDAdmin\\Documents\\SliceEngine\\SliceEngine\\bin\\Debug\\saya.xml");
        XmlNodeList xnList = xml.SelectNodes("/Patient/Patient/Name");
        foreach (XmlNode xn in xnList)
        {
            string name = xn.InnerText;
            listBox21.Items.Add(name);                
        }
    }

这是在窗体2的代码。

private void button1_Click(object sender, EventArgs e)
    {
        if (textBox1.Text == "")
        {
            MessageBox.Show("Please enter keyword to search");
        }
        else 
        {
            //send data input to form1.
        }



谁能帮助我?谢谢

can anyone help me with this? thank you

===编辑===

我指的此链接来解决这个问题。有两种方法,我现在用的是第二种方法,它完美的作品。我哭出声来此。感谢大家对博客的所有者。

i am referring to this link to solve this problem. There are two ways and i am using the second method and it works perfectly. I am crying out loud for this. thank you to the blogger owner.

我还发现,为了查看数据,我需要在文本框和列表框不进行查看。我做了什么之前我尝试在列表框中查看。我不知道为什么,但就是这样。无论如何,这个问题解决!再次为那些谁帮我看看这个问题,谢谢。我很感激​​。

i also found that, in order to view the data, i need to view it in TextBox and not ListBox. what i did before is im trying to view this in ListBox. i am not sure why but that is it. anyway, this problem SOLVE! thanks again for those who help me with this topic. i am grateful.

推荐答案

创建Form2上一个属性(或属性)暴露你想要的控件的值。所以如果你想搜索词不喜欢它:

Create a property (or properties) on Form2 exposing the values of the controls you want. So if you want the search term do it like:

public string SearchTerm
{
   get { return this.textBox1.Text; }
}



此外,在一个侧面说明;不要忘记检查,如果用户实际做新闻搜索。

Also, on a side-note; don't forget to check if the user actually did press search.

您现在的样子,当用户关闭与X也将搜索形式。 。这似乎不符合逻辑的用户

The way you have it now, when a user closes the form with the x it will also search. That doesn't seem logical to the user.

请在你的窗体2 ModalResult.OK按钮,像这样做:

Make the button on your Form2 ModalResult.OK and do it like this:

if (form2.ShowDialog() == ModalResult.OK)
{
  // Do your thing
}

这篇关于得到2并显示数据的用户输入在Form1在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆