PC Review


Reply
Thread Tools Rate Thread

Button control questions

 
 
Chris Dunaway
Guest
Posts: n/a
 
      12th Aug 2004
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.
 
Reply With Quote
 
 
 
 
Mick Doherty
Guest
Posts: n/a
 
      13th Aug 2004
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


 
Reply With Quote
 
Chris Dunaway
Guest
Posts: n/a
 
      16th Aug 2004
On Fri, 13 Aug 2004 15:15:46 +0100, Mick Doherty wrote:

> My Button source can be found at http://dotnetrix.co.uk/buttons.html


I tried connecting to your site but it would not come up. Is there another
site I could find the code?
--
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.
 
Reply With Quote
 
Mick Doherty
Guest
Posts: n/a
 
      16th Aug 2004
The link works here, but I know that there may be a problem going directly
to the page which is caused by the site being Framed by my Host, the same
reason why you wont find it via any search engine.

The page's real location is:
http://homepage.ntlworld.com/mdaudi1...e/buttons.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcglobal[dot]]net"> wrote in
message news:16kouq9vcls22.1p83j4b8nqp37$.(E-Mail Removed)...
> On Fri, 13 Aug 2004 15:15:46 +0100, Mick Doherty wrote:
>
>> My Button source can be found at http://dotnetrix.co.uk/buttons.html

>
> I tried connecting to your site but it would not come up. Is there
> another
> site I could find the code?
> --
> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SAME MACRO DON’T WORK ON (ActiveX Control) BUTTON BUT WORKS ON (From Control) BUTTON K Microsoft Excel Programming 3 16th Jun 2008 11:34 PM
How to set a button from a user control the default button on an aspx page AlecL Microsoft ASP .NET 2 12th Feb 2007 09:15 PM
send message to win32 app to press button control - remote control button Danny Microsoft C# .NET 2 2nd Feb 2007 02:10 PM
Custom button from a Control class doesn't appear as a choice for OK/Cancel button in a Form properties CroDude Microsoft C# .NET 3 28th Jun 2005 06:27 PM
Newbie questions: Toolbar control - Custom size for each button - possible? Dave Smithz Microsoft Dot NET 1 22nd Apr 2005 03:59 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:33 PM.