473,837 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
+ 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 23128
"Scott Emick" <se****@ham.f ox-international.c om> wrote in
news:#p******** ******@TK2MSFTN GP15.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********@rog ers.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.f ox-international.c om> wrote in message
news:%2******** ********@TK2MSF TNGP15.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.f ox-international.c om> 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.f ox-international.c om> 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 'InitializeComp onent' 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_lunch meat_[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
40318
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
13278
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. I went ahead and wrote my own bit of code so I'm sharing it here for everyone. Even though it doesn't really disable the button by greying it out, it prevents the multiple submissions which it what I was attempting to prevent all along. ...
3
2309
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 WebApplication1 { using System;
10
4405
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); this.Controls.Add (control); // I change the content of the html of the control. TextReader reader = new StreamReader (path);
7
1970
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 : parent.document.forms.submit(); Unfortunately, this fires off all the validation controls on the page, and I'd rather it didn't. Any ideas how I can submit the form programmatically without firing the
8
5011
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 readonly form (with no write access). But i cannot find any easy way of doing this, i've tried using the OnEnabledChanged() event, & exposing such other custom events.
4
6637
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 *know* will work is to disable all tab stops on all controls. This brute force method doesn't seem like a good idea though. What I wanted to do was take control the control enter/leave and mouse enter/leave and "switch back" the focus when it is...
5
3312
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 want user to do anything else on the page. We want to disable everything. I have following javascript on all of my pages (which is supposed to work), but it doesn't work. <script language="JavaScript"> function ignoreinput() { return false;
5
11284
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: for (int i = 0; i < 160; i++) { string checkbox = "checkBox" + i.toString(); (Cast)checkbox.enabled = false;
0
9682
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
10566
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10623
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7806
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
7000
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
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
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
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3124
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.