473,386 Members | 1,710 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Button control questions

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.
Nov 21 '05 #1
3 1524
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:yr*****************************@40tude.net...
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
Nov 21 '05 #2
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.
Nov 21 '05 #3
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:16******************************@40tude.net.. .
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
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
1
by: Divya | last post by:
Hello This is my 1st project where I have to create a Webcontrol. I have created a simple custom control with a button and 2 labels added to a panel. My problem is that the event handler that I...
33
by: Brian | last post by:
I have a list of plain HTML radio buttons that I want to be able to loop through, get the values from them and insert them into a db. each one should be a separate record... Can anyone please give...
14
by: Kevin | last post by:
A couple of easy questions here hopefully. I've been working on two different database projects which make use of multiple forms. 1. Where's the best/recommended placement for command buttons...
4
by: Alex Chun | last post by:
How can I program a command button on a form to bring up the standard "Find and Replace" dialog on click? Separate but related: how do you run menu commands (e.g. "Edit" "Find") from VB? ...
1
by: JasonK | last post by:
I would like to move the Delete button such that it displays one time in the footer row, rather than on every row. I've seen lots of questions asked on the subject around the net, but no answer...
1
by: Peted | last post by:
is it possible to use a lineargradientbursh to paint a gradient onto a button control, but have the button keep all its functionality, and visual functions, so that it still looks like a...
8
by: =?Utf-8?B?VGFtbXkgTmVqYWRpYW4=?= | last post by:
I am working with Visual C# window and in my application I need to use a button ( NEXT) . The button should displays one panel with its objects each time it clicked. I already developed the codes...
6
by: Dean Slindee | last post by:
When you drop a button on a form, a Click event is created by the designer. Within the Click event certain event parameters are defined: Private Sub btnInsert_ButtonPressed(ByVal sender As...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.