❔ 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
Relevant2y 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
TheUnrealGuyOP2y ago
I am using the FastColoredTextBox so there is a text box in the tab
Relevant
Relevant2y ago
So the textbox is what you want your textchanged event on
TheUnrealGuy
TheUnrealGuyOP2y ago
I can't figure out how to make an event handler yes the variable is called CurrentTB Current (TextBox)
Relevant
Relevant2y 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
Relevant2y ago
Relevant
Relevant2y 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
TheUnrealGuyOP2y ago
I tried doing that but I couldn't find it the CurrentTB like the textbox that is in a tab
Relevant
Relevant2y ago
Just double click the textbox
TheUnrealGuy
TheUnrealGuyOP2y ago
I can't, the textbox is created when I press the new tab button
Angius
Angius2y ago
Get a reference to that textbox, then, and add an event manually theTextbox.OnTextChanged += SomeEventHandlerMethod should do the trick
Relevant
Relevant2y ago
Yep, my bad, didn't realize it was dynamically generated
Angius
Angius2y ago
Error?
TheUnrealGuy
TheUnrealGuyOP2y ago
I tried doing this but it didn't work
TheUnrealGuy
TheUnrealGuyOP2y ago
It didn't do anything
Angius
Angius2y ago
Let me rephrase: what are the errors that occur in the code you posted in this screenshot?
TheUnrealGuy
TheUnrealGuyOP2y ago
There were no errors, it just didn't do anything.
Angius
Angius2y ago
I see red underlines
TheUnrealGuy
TheUnrealGuyOP2y ago
not this one I was talking about this one
Angius
Angius2y ago
Well this one just... declares a method It's not set to be a handler of any event Anywhere
TheUnrealGuy
TheUnrealGuyOP2y ago
I tried doing private void CurrentTB_TextChanged CurrentTB is the textbox variable when you create a new tab
Angius
Angius2y ago
So... add this method you have there as an event handler for CurrentTB's TextChanged event
TheUnrealGuy
TheUnrealGuyOP2y ago
I typed out that event handler myself.
Angius
Angius2y 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
Accord2y 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.
Want results from more Discord servers?
Add your server