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.OnMouseD own(mevent)
bClicked = True
Me.Invalidate()
End Sub
Protected Overrides Sub OnMouseUp(...)
MyBase.OnMouseU p(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_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address. 3 1539
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_sbcg lobal[dot]]net"> wrote in
message news:yr******** *************** ******@40tude.n et... 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.OnMouseD own(mevent) bClicked = True Me.Invalidate() End Sub
Protected Overrides Sub OnMouseUp(...) MyBase.OnMouseU p(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_lunch meat_[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
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_lunch meat_[DOT]net
To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
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_sbcg lobal[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_lunch meat_[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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 to: if one is clicked, its corresponding information will
become available on another document, if it's not clicked no
information will be provided. If multiple buttons are clicked their
information will available on the same document.
I'm not...
|
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 have assigned to the button , is not getting invoked. Could anyone please go thru the code and let me know what I am missing here? Thanks in advance
My custom control is as follows
using System
using System.Web
using System.Web.UI
using...
|
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 me some kind
of example on how to do this???? I am doing this in asp.net VB.
Please let me know if you need any additional information.
Thanks
|
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 for things
like delete, save, edit, cancel buttons - in the footer, or on the form
detail section?
2. If in the footer, how do you add them to the tab order?
|
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?
Thanks in advance!
Alex
| |
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 that seems to solve the problem.
I have tried a few things:
- adding a button, setting it's command name to Delete. Problem with this
is that the CommandArgument value does not get set to the SelectedIndex of
the GridView. Instead it has the...
|
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 "depressed" button
when clicked on ?
thanks for any help
peted
|
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 for creating panels and their
objects which will be questions and their answers. When the NEXT button
clicked it suppose to display first panel with one question and its answers
at a time. When the user selects an answer and click on NEXT button...
|
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 System.Object, ByVal e
As System.EventArgs)
What harm or limitations would ensue if (ByVal sender As System.Object,
ByVal e As System.EventArgs) were changed to ().
Thanks,
Dean S
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |