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

Setting up an event handler on a user-defined control

Liz
As a newbie I have been trying to set up an event handler
in my user-defined control to trigger an event in my form
when lblSelectedClient.Text changes. I get an error on my
event definition (****error here on event - says expected
class, delegate, enum, interface or struct ****). The
code is below. Can anyone see what I've done wrong?? I'm
at a loss.

Liz
public class ClientSearchEventArgs : EventArgs
{
public readonly string selectedClient;
public ClientSearchEventArgs(string selectedClient)
{
this.selectedClient = selectedClient;
}
}

//define the prototype of the callback method
public delegate void ChangedEventHandler(
object sender, ClientSearchEventArgs args);

//define the event
public event ChangedEventHandler Changed;
****error here on event - says expected class, delegate,
enum, interface of struct ****

//notify the registered objects of the event
protected virtual void OnChanged(
ClientSearchEventArgs e)
{
//if any object registered with the event
if (Changed != null)
{
//notify that object
Changed(this, e);
}

}
//Fire Change event when there is any
//change to the lblSelectedClient Text
//(attached to TextChanged event)
private void lblSelectedClient_TextChanged(object
sender, System.EventArgs e)
{
ClientSearchEventArgs args = new
ClientSearchEventArgs(
lblSelectedClient.Text);
OnChanged(args);
}
Nov 15 '05 #1
1 2484
Liz
Sorry folks, I've sorted it myself. It all came down to
one bracket in the end. I had this code within the
namespace rather than within the class! This bracket
thing is a real pain.
-----Original Message-----
As a newbie I have been trying to set up an event handlerin my user-defined control to trigger an event in my formwhen lblSelectedClient.Text changes. I get an error on myevent definition (****error here on event - says expectedclass, delegate, enum, interface or struct ****). The
code is below. Can anyone see what I've done wrong?? I'm
at a loss.

Liz
public class ClientSearchEventArgs : EventArgs
{
public readonly string selectedClient;
public ClientSearchEventArgs(string selectedClient)
{
this.selectedClient = selectedClient;
}
}

//define the prototype of the callback method
public delegate void ChangedEventHandler(
object sender, ClientSearchEventArgs args);

//define the event
public event ChangedEventHandler Changed;
****error here on event - says expected class, delegate,
enum, interface of struct ****

//notify the registered objects of the event
protected virtual void OnChanged(
ClientSearchEventArgs e)
{
//if any object registered with the event
if (Changed != null)
{
//notify that object
Changed(this, e);
}

}
//Fire Change event when there is any
//change to the lblSelectedClient Text
//(attached to TextChanged event)
private void lblSelectedClient_TextChanged(object
sender, System.EventArgs e)
{
ClientSearchEventArgs args = new
ClientSearchEventArgs(
lblSelectedClient.Text);
OnChanged(args);
}
.

Nov 15 '05 #2

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

Similar topics

10
by: SunshineGirl | last post by:
In my code, class A instanciates classes B and C. I would like class B to connect an event handler to a method in class A, and for class C to disconnect that event handler. I think I've done...
5
by: Russell Smallwood | last post by:
Hello all, Why can't I wire up an event during the "Raise PostBackEvent" stage of a postback? Just in case this is the wrong question, the situation: deep in the bowls of some code-behind...
13
by: Charles Law | last post by:
Mr "yEaH rIgHt" posted the following link about a week ago in answer to my question about removing event handlers. > http://www.vbinfozine.com/t_bindevt.shtml Following on from that post, the...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
8
by: hanseymoon | last post by:
How do you create a text input box, which shows a default value of 1+ and blocks the user from deleting it? Thanks so much! :))
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
6
by: John H Clark | last post by:
I am designing a site that requires AnonymousID. I set my web.config to allow this using <anonymousIdentification enable="true".../as recommended in the documentation. To verify the settings I...
1
by: tdan | last post by:
I do not know how to get Event.stopObserving() to work in the context I am using it. I am displaying a Color Selection Table and attaching 2 events: 1. onmouseover to display the color to the user...
4
by: eggie5 | last post by:
I have this even handler (using prototype.js): showCommentsLinks.observe('click', function(event) { alert('hi') }); It's attaching to a link element: <a id="showCommentsLink"...
3
by: Chamnap | last post by:
Hello everybody, I have one problem. I want to do something after the user finished scrolling. The scroll event fires whenever the user is scrolling. I don't want this actually. Does anyone has...
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:
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...
0
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...

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.