It's not you, it's the button control. It has one or two strange features
which, offhand, I can't remember. You may like to look at my button source
and see if that fixes your problem. If I remember correctly, one bug was
that if a button with focus contains the cursor, and you press and hold the
pace bar, move the cursor away from the button and release the spacebar, you
will find that the button recieves a click event when a mouse button is
clicked outside the button. The solution to this was to call OnLostFocus()
in the OnClick() and OnDoubleClick() methods.
My Button source can be found at
http://dotnetrix.co.uk/buttons.html
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:yrgwptvjvck7$.7rnip86o35er$.(E-Mail Removed)...
>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.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (
http://www.grisoft.com).
Version: 6.0.737 / Virus Database: 491 - Release Date: 11/08/2004