I have two forms (Form1 and Form2) that I would like to pass a string of characters between after a process completes on Form1.
On Form1, there is a text box that I would like to update with this string of characters. On Form2, I have a list box that contains the values that will eventually be loaded into this text box on Form1 after every process that completes. Basically what I am trying to do is to queue the next string that will be placed in the text box on Form1.
I have tried the creating a public property in Form2 as seen below:
public string NextString { get { return ListBox1.Items[ListBox1.TopIndex].ToString(); } }
Then, in Form1:
Form2 frm = new Form2();
string next = frm.NextString;
TextBox1.Text = next;
And presto. Except not. This was not working for me, unfortunately. I did some research and saw that this method was not quite the best practice and read that using event handlers was the more practical approach. So I researched those. I know that I have to create a new EventArgs class, a new public event, a firing method, how I want to handle the event, and then the handler method in Form1. This post is where I read into that.
I've played around with manipulating the answer to suit my needs:
public class StringEventArgs : EventArgs
{
public string NextString { get; set; }
public StringEventArgs(string data)
{
NextString = data;
}
}
A new event:
public event EventHandler<ListEventArgs> NewFileAdded;
This is where I got lost. I'm having a hard time understanding what is going on now. If anyone can help me completed what I am trying to do, I would be very grateful!