[RESOLVED] How to make a variable to act on events like Textbox.TextChanged
Hello again!
As stated in the title, I'm wondering if there is a method to create a variable which will act on events like Textbox.TextChanged?
I've done some research on the web, but I don't seem to get anywhere. However, as also mentioned in my other thread,
(http://www.vbforums.com/showthread.p...21#post4828321)
Niya's multi threading article has a working method, but I'm not sure how to make it all clean. Like just a sub which will react on the TextChanged event.
I hope anyone with this knowledge is willing to give me the answer :)
Kind regards,
- Frek
Re: How to make a variable to act on events like Textbox.TextChanged
Your request doesn't actually make sense. Variables don't act on events. A variable is just a place to store some data. You put data in and get that data out. That's it. As for events, they get raised and then any methods registered to handle them are executed. That's it. Perhaps you could provide a FULL and CLEAR explanation of the problem.
Re: How to make a variable to act on events like Textbox.TextChanged
I read through my post a couple of times, and I got an idea. It worked. I feel very sorry for asking this question now, but it might be useful for other new people. The code was as simple as this:
Code:
'Variable
Private WithEvents myTextChanged As New TextBox
'Sub
Private Sub myTextChanged_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myTextChanged.TextChanged
MsgBox(myTextChanged.Text) 'Displays the message given.
End Sub
'Call method
myTextChanged.Text = "My new string"
I don't really think this belongs in this forum, but maybe the code bank?
Anyway, have a nice day guys!
- Frek
Re: How to make a variable to act on events like Textbox.TextChanged
Quote:
Originally Posted by
jmcilhinney
Your request doesn't actually make sense. Variables don't act on events. A variable is just a place to store some data. You put data in and get that data out. That's it. As for events, they get raised and then any methods registered to handle them are executed. That's it. Perhaps you could provide a FULL and CLEAR explanation of the problem.
Thanks for showing interest in my request! I'm sorry my request didn't make sense, and I will try to be more accurate in the future. I simply wanted a variable to act like a textbox. Like when the textbox's text was changed, an event would happen (TextChanged). I was looking for the same feature with variables. I though about this a couple of times, and why not use a textbox with no UI instead? I guess there is a reason why it works this way, and my request was probably that reason. There is no need for an event to happen when a variables content is changed, as you can use other objects, such as a textbox. Then as you said, a variable is just there to input or output stored information.
- Frek
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
I'm glad you were able to find a solution by using a textbox, but just to expand on the subject a bit, if the textbox class didn't exist, the way to achieve the result you were after would have been by creating a class that would store your variable, and adding a custom event to react when that variable is changed through a class property.
Here is how you can create custom events: http://www.codeproject.com/Articles/...lass-in-VB-Net
Hope this helps.
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
Just to expand on Alains post, it could be a simple as this....
VB Code:
Private _myProp As String
Public Event myProp_Changed()
Public Property myProp() As String
Get
Return _myProp
End Get
Set(ByVal value As String)
If value <> _myProp Then
value = _myProp
RaiseEvent myProp_Changed()
End If
End Set
End Property
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
Quote:
Originally Posted by
Alain
I'm glad you were able to find a solution by using a textbox, but just to expand on the subject a bit, if the textbox class didn't exist, the way to achieve the result you were after would have been by creating a class that would store your variable, and adding a custom event to react when that variable is changed through a class property.
Here is how you can create custom events:
http://www.codeproject.com/Articles/...lass-in-VB-Net
Hope this helps.
Quote:
Originally Posted by
kebo
Just to expand on Alains post, it could be a simple as this....
VB Code:
Private _myProp As String
Public Event myProp_Changed()
Public Property myProp() As String
Get
Return _myProp
End Get
Set(ByVal value As String)
If value <> _myProp Then
value = _myProp
RaiseEvent myProp_Changed()
End If
End Set
End Property
I can't thank you guys enough! This is exactly what I was looking for. No, seriously, I really mean it. I can say you guys just improved the performance of my software! You have my respect :)
- Frek
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
I had already shown you this in your last thread how to raise events. Events should only ever be raised in One place. Read JMC's blog above in his signature that has a detailed tutorial on events.
Re: [RESOLVED] How to make a variable to act on events like Textbox.TextChanged
Quote:
Originally Posted by
ident
I had already shown you this in your last thread how to raise events. Events should only ever be raised in One place. Read JMC's blog above in his signature that has a detailed tutorial on events.
Specifically here:
http://jmcilhinney.blogspot.com.au/2...om-events.html