glasswizzard
Well-known member
- Joined
- Nov 22, 2019
- Messages
- 126
- Programming Experience
- Beginner
Hi, here is the situation, Form1 has a TextBox, Form2 has a ListBox, the TextBox will send it's text string when it is updated (after a second of inactivity) and the ListBox will be updated with the text as a new item, a simple (hah!) history of the textbox's previous contents.
There is another event I'll need (to go in reverse, when a listbox item is double clicked, the string will go to the textbox) but I'll not ask about that, I'll keep it simple, I imagine once I know how to do one, I can do the other.
Here's what I understand so far (or think I do at least), please correct me if anything below is wrong.
So after reading the links provided in my other thread I know there are four steps to this:
1) Create the event arguments
2) Create an event that uses the arguments
3) Make a method to raise the event
4) Make a method to handle the raised event
So I'll stick with step 1 one for now, get some clarification, and use the example provided in the link to base my own on which I renamed and pasted below:
So the eventargs will just be a string (the new text in the textbox).
What I'm wondering is do I need both set and get? I think so right? Once the event is raised it will set the new text from the textbox as the event arguments and the listbox will get the text. Am I understanding this right?
Also, the link did not tell me where to put this code so I'm guessing it goes in the namespace section of my main forms cs file?
I'd like to add that this first part seems to be the most confusing for me, everything beyond this first point does seem much more understandable but I'll guess we'll find out if that's true
There is another event I'll need (to go in reverse, when a listbox item is double clicked, the string will go to the textbox) but I'll not ask about that, I'll keep it simple, I imagine once I know how to do one, I can do the other.
Here's what I understand so far (or think I do at least), please correct me if anything below is wrong.
So after reading the links provided in my other thread I know there are four steps to this:
1) Create the event arguments
2) Create an event that uses the arguments
3) Make a method to raise the event
4) Make a method to handle the raised event
So I'll stick with step 1 one for now, get some clarification, and use the example provided in the link to base my own on which I renamed and pasted below:
C#:
public class TextUpdatedEventArgs : EventArgs
{
public string NewText { get; set; }
}
So the eventargs will just be a string (the new text in the textbox).
What I'm wondering is do I need both set and get? I think so right? Once the event is raised it will set the new text from the textbox as the event arguments and the listbox will get the text. Am I understanding this right?
Also, the link did not tell me where to put this code so I'm guessing it goes in the namespace section of my main forms cs file?
I'd like to add that this first part seems to be the most confusing for me, everything beyond this first point does seem much more understandable but I'll guess we'll find out if that's true