473,221 Members | 2,082 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,221 software developers and data experts.

how do I disable events for controls on a form?

How can I disable events for the controls on a form? I tried setting the
form's enable property to false, but that doesn't stop events from firing on
its controls.

I need to temporarily disable a form and load values into controls without
any events firing, then re-enable the form.

--
Scott Emick
Web Programmer
Fox International
Remove the ham from mail address if it's not spam
Nov 21 '05 #1
7 22885
"Scott Emick" <se****@ham.fox-international.com> wrote in
news:#p**************@TK2MSFTNGP15.phx.gbl:
I need to temporarily disable a form and load values into controls
without any events firing, then re-enable the form.


You can use AddHandler/RemoveHandler to add/remove events dynamically.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 21 '05 #2
Bob
I suspect you could do it with reflection by scanning for delegates attached
to each control's events, recording them, removing them, and then adding
them back again later. But do you really need to do that? For most
applications that's like shooting a squirrel with a shotgun. Might even be
considered bad design. I'm 90% sure you can get away with something simpler:

1. Load values into the controls before they're added to the form.
2. Declare a boolean variable IgnoreEvents and check it in all relevant
event-handling code.
3. Manually add and remove event handlers with AddHandler and RemoveHandler.

The first is ideal because it's the simplest but it's not always feasible. I
would lean towards #2 because it makes your code more explicitly stateful:
while debugging, the flow of execution to always hit the handler, you'll
always be able to tell when an event was fired, without having check if the
handler's been removed. What if something goes wrong and the handler isn't
put back? That's a bit harder to track down than just seeing that a variable
'IgnoreEvents' is still set to True. Make IgnoreEvents a Property and you'll
also be able to break on when it's set to a new value.

Bob

"Scott Emick" <se****@ham.fox-international.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
How can I disable events for the controls on a form? I tried setting the
form's enable property to false, but that doesn't stop events from firing on its controls.

I need to temporarily disable a form and load values into controls without
any events firing, then re-enable the form.

--
Scott Emick
Web Programmer
Fox International
Remove the ham from mail address if it's not spam

Nov 21 '05 #3

"Scott Emick" <se****@ham.fox-international.com> wrote
How can I disable events for the controls on a form? I tried setting the
form's enable property to false, but that doesn't stop events from firing on
its controls.


Have you tried setting each control's Enabled property?

LFS
Nov 21 '05 #4
"Scott Emick" <se****@ham.fox-international.com> schrieb:
How can I disable events for the controls on a form? I
tried setting the form's enable property to false, but that doesn't
stop events from firing on its controls.


Add the handlers to the controls' events after 'InitializeComponent' using
'AddHandler'. Notice that you will have to remove the 'Handles...' after
the event handlers added by VS.NET in order to prevent the handlers from
being associated with the events when the controls are instantiated.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #5
Scott,

To help you to decide I go for the answer from Lucas

Cor
Nov 21 '05 #6
I have the same problem. When I load a form, in the load event, I want to
initialize some text boxes with varying text. However, in the
textbox_Changed event, I also have code to process the new text and this
event fires evertime I change the text box contents. Setting a variable to
disable the changed event won't work because you have to reset before the
load event routine finishes in order to have the changed event go thru it's
processing. However, the textbox_changed events fire after the load event
compeletes. It's a catch 22 situation and I also would like some advice on
how to work this problem.

"Scott Emick" wrote:
How can I disable events for the controls on a form? I tried setting the
form's enable property to false, but that doesn't stop events from firing on
its controls.

I need to temporarily disable a form and load values into controls without
any events firing, then re-enable the form.

--
Scott Emick
Web Programmer
Fox International
Remove the ham from mail address if it's not spam

Nov 21 '05 #7
On Wed, 6 Oct 2004 14:27:01 -0700, Dennis wrote:
compeletes. It's a catch 22 situation and I also would like some advice on
how to work this problem.


Bob's suggestion of using a boolean to IgnoreEvents would work. In the
load event of the form, at the top, set IgnoreEvents = True then inside
each of the event handlers, check that variable and if set, exit the
handler instead of processing. Then, at the end of the load event, set
IgnoreEvents back to False.

--
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 #8

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

Similar topics

8
by: ORC | last post by:
Hi, Is it possible to disable an event like e.g. disabling: private void textBox1_TextChanged(object....) ? Thanks, Ole
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
3
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace...
10
by: Umut Tezduyar | last post by:
It seems, it is caching it. The following code is an example for it. How can avoid from this. override void OnLoad (sender and eventargs) { Control control = this.LoadControl (path);...
7
by: Jo Inferis | last post by:
For reasons that are unlikely to become clear at the moment, I have a page with some validation controls on it which opens a dialog. The dialog does *stuff* and then closes with a call to : ...
8
by: Antuane | last post by:
please help, i'm trying to find a simple & easy way of enabling & disabling (generally making them readonly) most of the controls in my form. Cuz i want to create a form, for the user but only a...
4
by: Jon Slaughter | last post by:
Is there any method to temporarily disable focus changing?(I assume only method is tab or mouse?) This problem has been tieing me up for a while and nothing seems to work. The only thing that I...
5
by: Sehboo | last post by:
In my application, there are lot of processes which take several seconds. What we want is that once user clicks on a button (or link or whatever) and while we are processing that request, we don't...
5
by: masterej | last post by:
Developers, Is there any way to disable all checkboxes on a form? I have a form with 160 checkboxes and I want to be able to disable all of them. Is there a way I can do something like this: ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.