473,763 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Prevent the Click Event when a Button is Clicked

When I click a button I don't want the click event to fire. Is this
possible?

In fact, what I would really like is to be able to intercept the click
event, perform some action, and then prevent the click from passing through
to the button.

Any help or suggestions much appreciated.

Charles
Nov 20 '05
24 7701
Thanks Mick. It makes sense to avoid the interop if it is not necessary, so
I will use your suggestion.

Charles
"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:%2******** **********@TK2M SFTNGP10.phx.gb l...
Hi Charles

This method does not improve on Herfrieds, it just does away with InterOp.
The Class will look as follows:

\\\
Public Class UserControl1
Inherits UserControl

Private Const WS_EX_TRANSPARE NT As Int32 = &H20

Public Sub New()
SetStyle(Contro lStyles.Support sTransparentBac kColor, True)
Me.BackColor = Color.Transpare nt
End Sub

Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreatePa rams
cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARE NT
Return cp
End Get
End Property

Protected Overrides Sub OnPaintBackgrou nd(ByVal pevent As
PaintEventArgs)
'
End Sub

End Class
///
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Charles Law" <bl***@nowhere. com> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
Hi Mick

Which bit does this replace, or does it replace it all?

Charles


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004

Nov 20 '05 #21
Mick (& Herfried),
That's a keeper! I knew it was relatively easy, I just could not figure out
the words.

Hopefully I will remember where I kept it, the next time someone asks ;-)

Jay

"Mick Doherty"
<EX***********@ AND.REMOVE.SQUA REBRACKETS.[mdaudi100#ntlwo rld.com]> wrote in
message news:%2******** ********@tk2msf tngp13.phx.gbl. ..
No need for Interop.

\\\
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreatePa rams
cp.ExStyle = cp.ExStyle Or WS_EX_TRANSPARE NT
Return cp
End Get
End Property
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004

Nov 20 '05 #22
It's a good solution for this problem, however if you want to draw in the
window so as to make some parts Opaque or Semi Transparent, then you'll find
that there is a problem with zOrder painting, which is why I usually create
Shaped controls.

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"Jay B. Harlow [MVP - Outlook]" <Ja************ @msn.com> wrote in message
news:Oq******** *****@tk2msftng p13.phx.gbl...
Mick (& Herfried),
That's a keeper! I knew it was relatively easy, I just could not figure out the words.

Hopefully I will remember where I kept it, the next time someone asks ;-)

Jay

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Nov 20 '05 #23
I have done something similar with a combo box that I wanted to extend.
It is pretty easy to search and replace the variable declaration and
instance instantiation lines in the code. You could add a property like
Clickable with a default value of false, etc, and then when you want to
make all your buttons unclickable cycle through them and set their
Clickable property to false. It didn't end up being too bad for my
case.
Michael Isaacs - MCP

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 20 '05 #24
Hi Michael

I have settled on the idea from Herfried. Putting a transparent window in
front of my control does the trick. It is even easier as all my controls
inherit from my base control, so I only have to implement it in the base
class for it to work.

Thanks again.

Charles
"Michael Isaacs" <ga*****@exampl e.com> wrote in message
news:O%******** **********@TK2M SFTNGP09.phx.gb l...
I have done something similar with a combo box that I wanted to extend.
It is pretty easy to search and replace the variable declaration and
instance instantiation lines in the code. You could add a property like
Clickable with a default value of false, etc, and then when you want to
make all your buttons unclickable cycle through them and set their
Clickable property to false. It didn't end up being too bad for my
case.
Michael Isaacs - MCP

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 20 '05 #25

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

Similar topics

6
3946
by: Sally | last post by:
I need to be able to click in a subform and run code but at the same time I need to be able to scroll the records without running the code. I tried coding the Enter event of the subform control but when I try to scroll the records the code runs. The subform is continuous; all the controls are on one line and the detail section is not exsposed above or below the controls. I tried coding the detail Click event but nothing happened. I tried...
1
11155
by: Stan | last post by:
If a page has a button with event handler private void btnAdd_Click(object sender, System.EventArgs e) { ....... } this event handler fires every time I refresh the page in the browser with F5 AFTER the button was clicked.
2
2355
by: Liqun Xu | last post by:
Hallo NG, I created a Button with Click-Event dynamically: System.Web.UI.WebControls.Button bt_1 = new Button(); bt_1.Click += new EventHandler(bt_1_click); and I implemented the Funktion bt_1_click in which I created a second Button dynamically too. System.Web.UI.WebControls.Button bt_2= new Button();
5
6174
by: J McD | last post by:
Hi I have a DataGrid with an ImageButton column. When I click on an imagebutton I get a postback but it doesn't run the OnImgBtnClick method. I can actually comment out the line where I add this Click event to the ImageButton Column and it makes no difference, I still get a postback. This is driving me crazy...something seems to be causing an OnClick postback and it isn't my Click event I've included the code below....any help will be...
0
2955
by: Demetri | last post by:
I have created a web control that can be rendered as either a linkbutton or a button. It is a ConfirmButton control that allows a developer to force a user to confirm if they intended to click it such as when they do a delete. Everything is great. By and large it will be used in my repeater controls using the command event when the user clicks on it and so that event is working great. My issue is the Click event. When the control is...
2
2394
by: Chu | last post by:
Thanks everyone for taking a moment to read this. I've got a page where I use a LinkButton and I wire up a dynamic event to the button. When the user clicks the button, the event is fired as expected. In the event code for that button, a new LinkButton is added to the page and is wired up to yet a different event, however when clicked, the page is posted back but the event is not triggered. I'm assuming it has something to do with the...
2
20641
by: Rob Roberts | last post by:
Is there any way to prevent a ButtonField in a GridView from doing a postback when clicked? I want to use my own onclick handler to call window.open('SomePage.aspx') to display a page in a new browser window when the button is clicked. I tried doing this in the RowCommand postback event by doing this in the event handler: Response.Write("<script>window.open('SomePage.aspx');</script>");
11
4245
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked. How I stop the buttons from posting back when they are clicked? Thanks
5
4126
by: Diane Truyens | last post by:
Hi, I have a form with textboxes, a search button and a gridview. The textboxes are filled with default values so that the gridview should return all rows but not before the user has had the chance to change some of the textboxes and has clicked the search button. How can I avoid the gridview displaying all rows before the search button was clicked? Any Ideas? Thanks Diane
0
9386
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,...
0
10145
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, 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...
1
7366
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5270
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...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3917
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
bsmnconsultancy
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...

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.