Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 C#2.0: create event and handler with args

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Uniwares Posted - Jun 27 2008 : 11:21:12 AM
Another snippet to create an event with its own event argument.
It requires three snippet parameter: the event name (e.g.: DownloadCompleted, ActionStarted, etc.), the parameter type and the parameter name (which is also used to create a property in the event args)

It will create the delegate, the event, the eventarg class and two methods to fire the event.


#region Event $EventName$

/// <summary>
/// Event Arguments for $EventName$
/// </summary>
public class $EventName$EventArgs : EventArgs
{
	$ParameterType$ _$EventParameter$;

	public $EventName$EventArgs($ParameterType$ $EventParameter$)
	{
		this._$EventParameter$ = $EventParameter$;
	}

	public $ParameterType$ $EventParameter$
	{
		get { return _$EventParameter$; }
	}
}

public event System.EventHandler<$EventName$EventArgs> $EventName$;

public delegate void $EventName$Handler(object sender, $EventName$EventArgs e); 

/// <summary>
/// Raise the $EventName$ Event
/// </summary>
private void On$EventName$($EventName$EventArgs e)
{
	if($EventName$ != null)
	{
		$EventName$(this, e);
	}
}

/// <summary>
/// Raise the $EventName$ Event
/// </summary>
private void On$EventName$($ParameterType$ e)
{
	On$EventName$(new $EventName$EventArgs(e));
}

#endregion

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000