C
C#17mo ago
TheUnrealGuy

❔ How to create an event handler for a variable

I am currently developing a HTML editor that has tabs and a page that shows the output. The variable for the textbox in the current tab selected is called CurrentTB, how can I create a event handler (CurrentTB_TextChanged)?
25 Replies
Relevant
Relevant17mo ago
Is this WinForms? Oh, just saw the label thing I don't think it's the tab you want the event on, but the content of the tab, which I think is different. Been a while. 1 min, and I can take a look Yeah, the TabPage. There's an event TextChanged But that's probably not what you're looking for either, since you're not typing directly onto the TabPage, but some control in the TabPage
TheUnrealGuy
TheUnrealGuy17mo ago
I am using the FastColoredTextBox so there is a text box in the tab
Relevant
Relevant17mo ago
So the textbox is what you want your textchanged event on
TheUnrealGuy
TheUnrealGuy17mo ago
I can't figure out how to make an event handler yes the variable is called CurrentTB Current (TextBox)
Relevant
Relevant17mo ago
ahh I was thinking you meant that was the name of your tab, my bad Click on the control, open Properties, click the lightning bolt icon Then just double click on the event you want to create a handler for
Relevant
Relevant17mo ago
Relevant
Relevant17mo ago
And actually TextChanged is the default event for a textbox anyways, so the even easier way to do it would be to just double click the control itself
TheUnrealGuy
TheUnrealGuy17mo ago
I tried doing that but I couldn't find it the CurrentTB like the textbox that is in a tab
Relevant
Relevant17mo ago
Just double click the textbox
TheUnrealGuy
TheUnrealGuy17mo ago
I can't, the textbox is created when I press the new tab button
Angius
Angius17mo ago
Get a reference to that textbox, then, and add an event manually theTextbox.OnTextChanged += SomeEventHandlerMethod should do the trick
Relevant
Relevant17mo ago
Yep, my bad, didn't realize it was dynamically generated
Angius
Angius17mo ago
Error?
TheUnrealGuy
TheUnrealGuy17mo ago
I tried doing this but it didn't work
TheUnrealGuy
TheUnrealGuy17mo ago
It didn't do anything
Angius
Angius17mo ago
Let me rephrase: what are the errors that occur in the code you posted in this screenshot?
TheUnrealGuy
TheUnrealGuy17mo ago
There were no errors, it just didn't do anything.
Angius
Angius17mo ago
I see red underlines
TheUnrealGuy
TheUnrealGuy17mo ago
not this one I was talking about this one
Angius
Angius17mo ago
Well this one just... declares a method It's not set to be a handler of any event Anywhere
TheUnrealGuy
TheUnrealGuy17mo ago
I tried doing private void CurrentTB_TextChanged CurrentTB is the textbox variable when you create a new tab
Angius
Angius17mo ago
So... add this method you have there as an event handler for CurrentTB's TextChanged event
TheUnrealGuy
TheUnrealGuy17mo ago
I typed out that event handler myself.
Angius
Angius17mo ago
So... add this method you have there as an event handler for CurrentTB's TextChanged event There's no magic Just because a method is named a certain way doesn't automagically make it handle some event
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.