C
Chris Dunaway
I have derived a class from the System.Windows.Forms.Button class in order
to draw the button differently.
Among other things, I paint the background of the button in the OnPaing
override.
Next I wanted the background color to change when the button was clicked so
I overrided the OnMouseDown and OnMouseUp events like so: (pseudocode)
Protected Overrides Sub OnMouseDown(...)
MyBase.OnMouseDown(mevent)
bClicked = True
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseUp(...)
MyBase.OnMouseUp(mevent)
bClicked = False
Me.Invalidate()
End Sub
Elswhere in the paint event, I check the value of the boolean variable to
decide what color to paint:
Protected Overrides Sub OnPaint(...)
MyBase.OnPaint(pevent)
If bClicked Then
'Paint CLICKED color here
Else
'Paint UNCLICKED color here
End If
End Sub
This all seems to work correctly except for one thing. When I test the
button using a MsgBox in the buttons click event handler, the button
changes color when I click and the message box shows but the button's color
stays in the "clicked" state until I clear the MsgBox.
When I use a normal button, the visual state of the button immediately
reverts to the unclicked state before the MsgBox appears.
I wish to duplicate that in my class.
For example, I want to click the button have it change color to indicate
the click and then revert back to the unclicked state when I release the
mouse button. It seems that the Click event handler is getting called
before the OnMouseUp executes.
What am I doing wrong?
Chris
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
to draw the button differently.
Among other things, I paint the background of the button in the OnPaing
override.
Next I wanted the background color to change when the button was clicked so
I overrided the OnMouseDown and OnMouseUp events like so: (pseudocode)
Protected Overrides Sub OnMouseDown(...)
MyBase.OnMouseDown(mevent)
bClicked = True
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseUp(...)
MyBase.OnMouseUp(mevent)
bClicked = False
Me.Invalidate()
End Sub
Elswhere in the paint event, I check the value of the boolean variable to
decide what color to paint:
Protected Overrides Sub OnPaint(...)
MyBase.OnPaint(pevent)
If bClicked Then
'Paint CLICKED color here
Else
'Paint UNCLICKED color here
End If
End Sub
This all seems to work correctly except for one thing. When I test the
button using a MsgBox in the buttons click event handler, the button
changes color when I click and the message box shows but the button's color
stays in the "clicked" state until I clear the MsgBox.
When I use a normal button, the visual state of the button immediately
reverts to the unclicked state before the MsgBox appears.
I wish to duplicate that in my class.
For example, I want to click the button have it change color to indicate
the click and then revert back to the unclicked state when I release the
mouse button. It seems that the Click event handler is getting called
before the OnMouseUp executes.
What am I doing wrong?
Chris
--
Chris
dunawayc[AT]sbcglobal_lunchmeat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.