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