Click here to Skip to main content
15,887,450 members
Home / Discussions / C#
   

C#

 
AnswerRe: Process.workingset Pin
Luc Pattyn17-Jul-09 15:03
sitebuilderLuc Pattyn17-Jul-09 15:03 
Questionhelp Pin
unlucky_dreamer17-Jul-09 12:45
unlucky_dreamer17-Jul-09 12:45 
AnswerRe: help Pin
DaveyM6917-Jul-09 13:20
professionalDaveyM6917-Jul-09 13:20 
GeneralRe: help Pin
Michael Schubert17-Jul-09 22:06
Michael Schubert17-Jul-09 22:06 
QuestionMS Word Automation - Combining word documents Pin
venadder17-Jul-09 11:25
venadder17-Jul-09 11:25 
QuestionDelegates - I don't Get It Pin
eddieangel17-Jul-09 7:52
eddieangel17-Jul-09 7:52 
AnswerRe: Delegates - I don't Get It Pin
harold aptroot17-Jul-09 8:14
harold aptroot17-Jul-09 8:14 
AnswerRe: Delegates - I don't Get It Pin
CodingYoshi17-Jul-09 8:20
CodingYoshi17-Jul-09 8:20 
Delegates work like this:

public class Camera
{
// There is a delegate here which will inform you when the shutter button is pushed
}

public class SomeListener
{
// Here you add a handler for the delegate
// You create an instance of the delegate found in the Button class and provide it with a method
// The delegate will carry out the method for you
// Your method must have the same signature as the delegate in the Camera class
// Within your method you will do something you want
}

Here is a button class which has a single event. The comments will guide you.

public class AButton
{
// This is the delegate
public delegate void ButtonClickedHandler(AButton sender, EventArgs e);

// This is an event which is basically an instance of the delegate
public event ButtonClickedHandler Click;

// Here is a method which will raise the click event
public void ClickMe()
{
// In C# first you check if anyone has created an instance of your delegate
// Whoever has created an instance is called the subscriber or listener
if (Click != null)
{
Click(this, EventArgs.Empty); // Call the listener's method that has this signature and let it do whatever it needs to
}
}

Here is a listener:

public class Listener
{
// First create an instance of the class
public Listener()
{
AButton b = new AButton();

// Now listen to the event
// Remember the delegate requires you to pass to it a method which has the same signature as the delegate
// This is like saying: "Hey a (which is an instance of AButton), when you are clicked please do what I want
// you to do in AButton_Click method.
b.Click += new Click(AButton_Click);
}

// Here is the method
private void AButton_Click(AButton sender, EventArgs e) // Same signature
{
MessageBox.Show("The button was clicked and this is all I want to do.");
}
}

}
}

CodingYoshi

Artificial Intelligence is no match for Human Stupidity.

GeneralRe: Delegates - I don't Get It Pin
eddieangel17-Jul-09 8:35
eddieangel17-Jul-09 8:35 
GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 10:47
professionalDaveyM6917-Jul-09 10:47 
GeneralRe: Delegates - I don't Get It Pin
eddieangel17-Jul-09 11:00
eddieangel17-Jul-09 11:00 
GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 11:26
professionalDaveyM6917-Jul-09 11:26 
GeneralRe: Delegates - I don't Get It Pin
DaveyM6917-Jul-09 11:39
professionalDaveyM6917-Jul-09 11:39 
AnswerRe: Delegates - I don't Get It Pin
Luc Pattyn17-Jul-09 10:13
sitebuilderLuc Pattyn17-Jul-09 10:13 
GeneralRe: Delegates - I don't Get It Pin
Baeltazor17-Jul-09 22:28
Baeltazor17-Jul-09 22:28 
QuestionCrystalReports Pin
CodingYoshi17-Jul-09 7:06
CodingYoshi17-Jul-09 7:06 
AnswerRe: CrystalReports Pin
Adam R Harris17-Jul-09 9:20
Adam R Harris17-Jul-09 9:20 
GeneralRe: CrystalReports Pin
Adam R Harris17-Jul-09 10:41
Adam R Harris17-Jul-09 10:41 
GeneralRe: CrystalReports Pin
CodingYoshi17-Jul-09 10:54
CodingYoshi17-Jul-09 10:54 
QuestionCommon components in C# and .net? Pin
saxisa17-Jul-09 7:01
saxisa17-Jul-09 7:01 
QuestionNTLM Authentication in C# Pin
joana.simoes17-Jul-09 5:39
joana.simoes17-Jul-09 5:39 
AnswerRe: NTLM Authentication in C# Pin
Adam R Harris17-Jul-09 9:25
Adam R Harris17-Jul-09 9:25 
GeneralRe: NTLM Authentication in C# Pin
joana.simoes19-Jul-09 23:34
joana.simoes19-Jul-09 23:34 
GeneralRe: NTLM Authentication in C# Pin
joana.simoes19-Jul-09 23:50
joana.simoes19-Jul-09 23:50 
AnswerRe: NTLM Authentication in C# Pin
joana.simoes20-Jul-09 3:30
joana.simoes20-Jul-09 3:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.