The event keyword is used to declare an event in a publisher class.
Events are a special kind of multicast delegate that can only be invoked from within the class or struct where they are declared (the publisher class). If other classes or structs subscribe to the event, their event handler methods will be called when the publisher class raises the event. For more information and code examples, see Events (C# Programming Guide) and Delegates (C# Programming Guide).
Events can be marked as public, private, protected, internal, or protected internal. These access modifiers define how users of the class can access the eventSyntax:
access_specifier event event_name;Example:
// custom delegate
public delegate void Startdelegate();
class Eventdemo : Form
// custom event
public event Startdelegate StartEvent;
Button clickMe = new Button();
clickMe.Parent = this;
clickMe.Text = "Click Me";
clickMe.Location = new Point(
(ClientSize.Width - clickMe.Width) /2,
(ClientSize.Height - clickMe.Height)/2);
// an EventHandler delegate is assigned
// to the button's Click event
clickMe.Click += new EventHandler(OnClickMeClicked);
// our custom "Startdelegate" delegate is assigned
// to our custom "StartEvent" event.
StartEvent += new Startdelegate(OnStartEvent);
// fire our custom event
// this method is called when the "clickMe" button is pressed
public void OnClickMeClicked(object sender, EventArgs ea)
MessageBox.Show("You Clicked My Button!");
// this method is called when the "StartEvent" Event is fired
public void OnStartEvent()
MessageBox.Show("I Just Started!");
static void Main(string args)
Java Enterprise Edition (EE)
Java Standard Edition (SE)
RFC (standard status)
RFC (proposed standard status)
RFC (draft standard status)
RFC (informational status)
RFC (experimental status)
RFC (best current practice status)
RFC (historic status)
RFC (unknown status)
All information of this service is derived from the free sources and is provided solely in the form of quotations.
This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 2999 / . Delta: 0.04609 с