❔ How to can I create a TextChanged event handler for this current text box property?

55 Replies
TheUnrealGuy
TheUnrealGuyOP2y ago
This CurrentTB property is the Current Text Box in the selected TabPage. How can I create a TextChanged event handler for the CurrentTB property?
Pobiega
Pobiega2y ago
Winforms? You can't set an eventhandler on a property and have it follow the property reference, so you'll need to add the eventhandler to ALL the textboxes and filter the event source in the handler itself
TheUnrealGuy
TheUnrealGuyOP2y ago
The CurrentTB property is the current selected text box in the selected tab page. Because I am making an HTML IDE with tabs and I need to make an event handler on the current selected text box.
Pobiega
Pobiega2y ago
Well, either have all of them be subscribed and filter, or manually register/unregister the events as the user changes tabs those are your options there is no silver bullet here
TheUnrealGuy
TheUnrealGuyOP2y ago
what do you mean by register/unregister?
Pobiega
Pobiega2y ago
you can subscribe to events with code, not just in the designer and you can unsubscribe too
TheUnrealGuy
TheUnrealGuyOP2y ago
subscribe? what is subscribing?
Pobiega
Pobiega2y ago
textBox.TextChanged += YourHandler; that subscribes to the textchanged event on that box, with the method on the right being the handler that will get invoked you can do -= to remove the eventhandler
TheUnrealGuy
TheUnrealGuyOP2y ago
Could I put this code in the load handler? Like MyApp_Load
Pobiega
Pobiega2y ago
in theory, but will the tabs be created on load?
TheUnrealGuy
TheUnrealGuyOP2y ago
the tabs will be created by pressing a toolstrip button
Pobiega
Pobiega2y ago
so not at load then the tabs, and the textboxes, must exist when you register. so I'd think you'll have to register when a tab is activated, if you want to go with that approach alternatively just keep track of the current active tab (and its textbox) and check if the event is being emitted from the current active box
TheUnrealGuy
TheUnrealGuyOP2y ago
@Pobiega The event handler thing worked, but my IDE has a split view of a browser which displays your work, and a tabcontrol that controls the current text boxes and such, when I try to make it so that the browser displays the current text box's HTML when you change the tabpage, it gives me an error.
Pobiega
Pobiega2y ago
that means CurrentTB was null
TheUnrealGuy
TheUnrealGuyOP2y ago
TheUnrealGuy
TheUnrealGuyOP2y ago
the text in the CurrentTB is null?
Pobiega
Pobiega2y ago
that, or webBrowser1 is and no not the text the CurrentTB itself
TheUnrealGuy
TheUnrealGuyOP2y ago
I don't understand, when you press the button it should create a tab with a CurrentTB text box. But this error shows when I try to create a new tab
Pobiega
Pobiega2y ago
use the debugger to figure out what is null
TheUnrealGuy
TheUnrealGuyOP2y ago
It is stating that "Object reference not set to an instance of an object"
Pobiega
Pobiega2y ago
yeah thats the text from "NullReferenceException" that means an object refernce was null, when you used it as if it wasnt
TheUnrealGuy
TheUnrealGuyOP2y ago
Pobiega
Pobiega2y ago
stack overflow usually means you have an infinite recursive loop ie, a method calling itself over and over
TheUnrealGuy
TheUnrealGuyOP2y ago
It is not showing me what is null
Pobiega
Pobiega2y ago
$debug
MODiX
MODiX2y ago
Tutorial: Debug C# code - Visual Studio (Windows)
Learn features of the Visual Studio debugger and how to start the debugger, step through code, and inspect data in a C# application.
TheUnrealGuy
TheUnrealGuyOP2y ago
where do I go here to debug?
Pobiega
Pobiega2y ago
read the guide use breakpoints inspect values
Pobiega
Pobiega2y ago
TheUnrealGuy
TheUnrealGuyOP2y ago
@Pobiega How do you make it so that when all tabs are closed, it closes the form? Like in an if statement.
Pobiega
Pobiega2y ago
You can probably register an event handler on tab close event and count the number of tabs
TheUnrealGuy
TheUnrealGuyOP2y ago
I tried doing something like this but it closes the form when I close one tab. (Items are the tab pages)
Pobiega
Pobiega2y ago
thats... a very weird if statement you're checking if the collection is not null you want to check that the collection has 0 items
TheUnrealGuy
TheUnrealGuyOP2y ago
how can I check that?
Pobiega
Pobiega2y ago
Im sure you can figure that out without handholding
TheUnrealGuy
TheUnrealGuyOP2y ago
this damn pack that I am using is just hurting my brain lmao
TheUnrealGuy
TheUnrealGuyOP2y ago
I just don't understand why this won't work.
Pobiega
Pobiega2y ago
what exactly does += do here, do you think?
TheUnrealGuy
TheUnrealGuyOP2y ago
I have no clue to be honest. I don't know why there has to be == or != or += what do they mean exactly?
Pobiega
Pobiega2y ago
they all do different things, suprisingly == is an equals comparison it checks if two values are equal != is the same, but checks for NOT equal += is the increment operator, it increases the left value by the right value
int val = 5;
val += 10;
val == 15 // true
int val = 5;
val += 10;
val == 15 // true
TheUnrealGuy
TheUnrealGuyOP2y ago
ahhh I see what would I put in there for this situation?
Pobiega
Pobiega2y ago
^
TheUnrealGuy
TheUnrealGuyOP2y ago
in the If statement if (tsFiles.Items == 0)?
Pobiega
Pobiega2y ago
yay you did it well, almost
TheUnrealGuy
TheUnrealGuyOP2y ago
bummer
Pobiega
Pobiega2y ago
tsFiles.Items isnt a numeric value its a collection
TheUnrealGuy
TheUnrealGuyOP2y ago
oh
Pobiega
Pobiega2y ago
you need to check a certain property ON the collection
TheUnrealGuy
TheUnrealGuyOP2y ago
If I go to the collection there would be the items and such in the collection
TheUnrealGuy
TheUnrealGuyOP2y ago
Pobiega
Pobiega2y ago
sigh tsFiles.Items.SOMETHING == 0 figure out what SOMETHING should be...
TheUnrealGuy
TheUnrealGuyOP2y ago
oh oh I am stupid as hell sometimes
TheUnrealGuy
TheUnrealGuyOP2y ago
Pobiega
Pobiega2y ago
yay
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