473,811 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event handling

VC
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.
Nov 15 '05 #1
3 1901
VC,

If you want to hook up a method on ACTRL to an event on the form, then
yes, you have to sign up for the event using the += operator. Or, if you
want other methods to be hooked up to an event that ACTRL fires, then you
need to hook those up using the same operator.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"VC" <us********@yah oo.com> wrote in message
news:be******** *************** ***@posting.goo gle.com...
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.

Nov 15 '05 #2
VC
Nicholas,

Thank you very much for your feedback. I have read a lot of messages
you posted in Google Group, they are very helpful.

In my project(C#,.NET ). some of usercontrols(AC TRL) need hook up to
the event that ACTRL fires. and some of them don't need. right now the
situation is that all of them have to be signed up to the event by
"+=". otherwise they throw "Object reference not set to an instance of
an object" exception.
what I want to do is if you need receive the event from the ACTRL,
sign up "+=" to event. if not, don't sign up. please let me know
anything wrong in my code.
Here is my code look like:

public delegate void InkCtrlUpdatedE vent(object o, string str);

public class ACTRL: System.Windows. Forms.UserContr ol
{
:
:
public event InkCtrlUpdatedE vent InkCtrlCellUpda ted;
:
:
private void fireEvent(strin g str)
{
InkCtrlCellUpda ted(this,str);
}
}

Again, thanks for the help.


us********@yaho o.com (VC) wrote in message news:<be******* *************** ****@posting.go ogle.com>...
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.

Nov 15 '05 #3
Try putting changing your fireEvent method to have the following code:

if(null != InkCtrlCellUpda ted)
{
InkCtrlCellUpda ted(this,str);
}

- Scott Wagner

VC wrote:
Nicholas,

Thank you very much for your feedback. I have read a lot of messages
you posted in Google Group, they are very helpful.

In my project(C#,.NET ). some of usercontrols(AC TRL) need hook up to
the event that ACTRL fires. and some of them don't need. right now the
situation is that all of them have to be signed up to the event by
"+=". otherwise they throw "Object reference not set to an instance of
an object" exception.
what I want to do is if you need receive the event from the ACTRL,
sign up "+=" to event. if not, don't sign up. please let me know
anything wrong in my code.
Here is my code look like:

public delegate void InkCtrlUpdatedE vent(object o, string str);

public class ACTRL: System.Windows. Forms.UserContr ol
{
:
:
public event InkCtrlUpdatedE vent InkCtrlCellUpda ted;
:
:
private void fireEvent(strin g str)
{
InkCtrlCellUpda ted(this,str);
}
}

Again, thanks for the help.


us********@yaho o.com (VC) wrote in message news:<be******* *************** ****@posting.go ogle.com>...
I created an usercontrol ACTRL. and I fired an event from the ACTRL.
in my form application, do all ACTRL controls have to do "+=" to sign
up the event? my problem is if the ACTRL control in the form app
doesn't sign up the event, the application will throw exception
"Object reference not set to an instance of an object" during the run
time.


Nov 15 '05 #4

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

Similar topics

7
49588
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
1
20705
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function init() {
4
12586
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
18
2893
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code that applies to all these events, but I need to have specific code execute when the form closes. The properties for this method are sender (the originator) and e (event arguments). I know how to get typeof (sender) to determine what form or...
8
6091
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that uses message queues to pass pointers to Events between threads. In my app there are simple events that can be defined using an enum (for example an event called NETWORK_TIMEOUT) and more complex events that contain data (for example an event called...
4
1755
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual protected method of the base class". Can someone please explain this with a sample code? Thanks a lot.
3
2081
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the following scenario Server (COM event source) is written in VC++ 6.0 using ATL (event interfaces can be either dispinterface / IDispatch based) Client (COM event receiver) is written in VC++ 2003 using attributed programming and unified event handling
2
2137
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the database. This works fine. However, I attempt to notify the user when data accesses occur. The way I attempt to accomplish this is by changing the background color of a label on the form the user is looking at. I use red for when the database is...
4
9701
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person writing the JavaScript doesn't have to pass the index in the "onChange" event name. I thought that one might be able to use "this.value" or compare this as
0
9605
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
10389
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
10402
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,...
0
9205
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, 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...
1
7670
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
6890
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
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
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
3018
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.