473,387 Members | 1,541 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,387 software developers and data experts.

generating events in user defined controls

I need to generate an event in a user defined control
when I have changed a variable, so that I can pick it up
in my main form and take it from there.

Can someone explain the SIMPLEST way of doing this.

Liz (newbie to OO)
Nov 15 '05 #1
2 1441
Liz,

Assuming that your variable is exposed as a property, you can do the
following:

// Assume the property is named MyProperty. Define your event like this:
public event EventHandler MyPropertyChanged;

This will define your event as type EventHandler. Then, when the value
changes, you can make the following call:

// Check to see if there are any events to fire.
EventHandler pobjHandlers = MyPropertyChanged;

// If there are handlers, then fire the event.
if (pobjHandlers != null)
// Fire the event.
pobjHandlers(this, EventArgs.Empty);

Then, your form would pick up the event like any other event. Also, the
name of the event and the type are important here. The reason I suggested
this is because naming the event like this makes your class fit more into
the data binding model (the data grid and property grid will pick up on the
property change, for example).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Liz - Newbie" <ec******@cornwall.gov.uk> wrote in message
news:08****************************@phx.gbl...
I need to generate an event in a user defined control
when I have changed a variable, so that I can pick it up
in my main form and take it from there.

Can someone explain the SIMPLEST way of doing this.

Liz (newbie to OO)

Nov 15 '05 #2
Liz
Bless you - it worked! I'm not certain quite how it all
works but it worked. I can now use this as a basis for
passing events back to my form. Thanks a million

Liz
-----Original Message-----
Liz,

Assuming that your variable is exposed as a property, you can do thefollowing:

// Assume the property is named MyProperty. Define your event like this:public event EventHandler MyPropertyChanged;

This will define your event as type EventHandler. Then, when the valuechanges, you can make the following call:

// Check to see if there are any events to fire.
EventHandler pobjHandlers = MyPropertyChanged;

// If there are handlers, then fire the event.
if (pobjHandlers != null)
// Fire the event.
pobjHandlers(this, EventArgs.Empty);

Then, your form would pick up the event like any other event. Also, thename of the event and the type are important here. The reason I suggestedthis is because naming the event like this makes your class fit more intothe data binding model (the data grid and property grid will pick up on theproperty change, for example).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Liz - Newbie" <ec******@cornwall.gov.uk> wrote in messagenews:08****************************@phx.gbl...
I need to generate an event in a user defined control
when I have changed a variable, so that I can pick it up in my main form and take it from there.

Can someone explain the SIMPLEST way of doing this.

Liz (newbie to OO)

.

Nov 15 '05 #3

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

Similar topics

1
by: Natalia DeBow | last post by:
Hi, I am working on a Windows-based client-server application. I am involved in the development of the remote client modules. I am using asynchronous delegates to obtain information from...
2
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control...
0
by: Scott McChesney | last post by:
I have a problem I hope you folks can help me with. I have an application that is using a tab-based interface, with the ability for users to drag an item from a ListBox onto the tab control. ...
11
by: Nicky Smith | last post by:
Hello, I'm studying a book on VB.net Win apps, and I'm reading a section on events and delegates and raising events. Is it just me, or is this not just subs dressed up as something else? I...
2
by: fix | last post by:
Hi all, I am just wondering if there is a way to generate Page_xxx events automatically instead of typing it in the code-behind file manually. For the controls on a webform, I can select them,...
0
by: Ashish | last post by:
HI all, I have been battling with this problem with some time now, now iam out of ideas what to do basically iam planning a tab control in which page developers can define tab abd tabelements on...
3
by: =?Utf-8?B?VDhS?= | last post by:
Ok...I've been looking for an answer to this problem and can't seem to find one...Framework 1.1 mind you. I have a base class that inherits from UserControl. I have 5 and soon to be 12 user...
1
by: johnson.bj | last post by:
I have a relatively minor problem that has been bugging me for a long time. I have created a user control which consists of a few panels and labels. What I want to do with this user control is to...
3
by: Anane | last post by:
I get following error when i press a command button. The expression click you entered as the event property setting produced the following error: method or data member not found. It gives me...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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...

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.