I have a windows form1 application. This form1 has a click button. When the button is clicked some events handler are created in the click-button method. In the SendText event handler method I a create and show a second Form2 where i want to print a string value met in form1.
The problem is the fact that in my ListBox I see just one string and not all of them (I am consecutively sending strings). Why? Plus there are no additional Form2 forms created and shown when a new event handler arrives.
In Form1 this is the way i am calling form2:
public void Send(string body, string name)
{
Form2 form2 = new Form2(body);
form2.Text = name;
form2.ShowDialog ();
}
public void OnMessage(first val, second vall)
{
send(string val1, string va2);
}
Form2 contains:
public Form2(string s)
{
InitializeComponent();
listBox1.Items.Add(s);
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
2 Questions:
-
How can i create multiple Form2 forms each time the handler is activated (using threads, no?)?
-
If first val is the same when a new handler arrives how can I activate the form2 that is already on the screen and add a new item in the ListBox1?
Please provide examples, if possible.
Thank you.
if i got this right, you want:
what about this?
(code not tested…)
you will possibly want to handle the FormClosing event of Form2 … cancel the event using the eventarg and call this.Hide() … so a Form2 will still disappear if the user klicks the x but the form is still there, ready to be reshown when the next event adds something to it …