473,473 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 22968
"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: ...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...
0
agi2029
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,...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.