Custom EventHandler

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
11 posts Page 1 of 2
Contributors
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Custom EventHandler
M1z23R
I want to create a custom event handler for my custom control...
My control inherits from a "button", button doesn't have CheckChanged event but i want to create it.
I built up my CheckButton control but now, i want to be able to create event for it when check changes...
Please help :D + rep
User avatar
Cheatmasterbw
Coding God
Coding God
Posts: 1506
Joined: Fri Jan 01, 2010 2:30 pm

Re: Custom EventHandler
Cheatmasterbw
viewtopic.php?f=21&t=5993

^^^ Look at this
http://www.megaapps.tk/
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Custom EventHandler
M1z23R
I did, but how can i "Set" on what change, what to do :/ if you understand me xD
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: Custom EventHandler
mandai
You could make a function to draw/clear a check on the button, then you could store the state as a property variable.
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Custom EventHandler
M1z23R
How do i do that :D

I have this
Code: Select all
 Private CheckState As Boolean

  Property Checked() As Boolean
        Get
            Checked = CheckState
        End Get
        Set(ByVal value As Boolean)
            CheckState = value
        End Set
    End Property
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Custom EventHandler
GoodGuy17
On CheckButton_Click, put:
Code: Select all
If CheckState = True Then
'Do something if it is checked
CheckState = False
Else
'Do something if it isn't checked
CheckState = True
End If
That way, you don't even have to have a new event, you can just make use of your current ones.
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Custom EventHandler
M1z23R
I did that, and i can change the state, but i want to be able to create like in a checkbox "CheckStateChanged", because if you change its state with another button like "CheckBox1.Checked = True" nothing else will happen, and i have "color changes, style..." and many more options that are on "click" event, and not change state
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Re: Custom EventHandler
GoodGuy17
So you want to be able to change the CheckState of the button from another object?

I didn't quite understand what you said. Can you rephrase it? It sounds like you want to change the state from another object.
User avatar
M1z23R
VIP - Donator
VIP - Donator
Posts: 622
Joined: Tue Sep 28, 2010 4:55 pm

Re: Custom EventHandler
M1z23R
Here is an example :

You have 2 "CheckButtons", and a button
Button :
Code: Select all
CheckButton1.Checked = True
CheckButton2.Checked = True
so, when you click button, CheckButtons "checked" state changes...

But my "CheckButton" handles color changes, style changes ... on "Click" event, so if you click checkbutton, everything is ok, but if you change its state from another control, only its state changes, not style,color ...
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: Custom EventHandler
MrAksel
use the RaiseEvent statement to raise an event, to declare it just use this:
Code: Select all
Public Event CheckStateChanged() 'you can have arguments between the parentheses
Code: Select all
  Private CheckState As Boolean

  Property Checked() As Boolean
        Get
            Checked = CheckState
        End Get
        Set(ByVal value As Boolean)
            If Not value = CheckState Then RaiseEvent CheckStateChanged() 'Arguments between the parentheses
            CheckState = value
        End Set
    End Property
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
11 posts Page 1 of 2
Return to “Tutorial Requests”