Click here to Skip to main content
15,903,203 members
Home / Discussions / C#
   

C#

 
AnswerRe: checkBox & TreeView Pin
TJoe26-Sep-07 3:28
TJoe26-Sep-07 3:28 
GeneralRe: checkBox & TreeView Pin
half-life26-Sep-07 3:42
half-life26-Sep-07 3:42 
QuestionWho am I? Detecting the "current" control for a handler [modified] Pin
JoeRip26-Sep-07 2:31
JoeRip26-Sep-07 2:31 
AnswerRe: Who am I? Detecting the "current" control for a handler Pin
Malcolm Smart26-Sep-07 2:35
Malcolm Smart26-Sep-07 2:35 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 2:41
JoeRip26-Sep-07 2:41 
AnswerRe: Who am I? Detecting the "current" control for a handler Pin
TJoe26-Sep-07 2:48
TJoe26-Sep-07 2:48 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 2:52
JoeRip26-Sep-07 2:52 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
TJoe26-Sep-07 3:01
TJoe26-Sep-07 3:01 
The "sender" parameter is the control that fired the event. I'm assuming that is what you are asking. The C# equilvalent of the VB.Net "Me" is "this".

So if you have two combo boxes and you hook them both up to the same event handler like:

private ComboBox comboBox1 = new ComboBox();
private ComboBox comboBox2 = new ComboBox();
  
private void CreateComboBoxes() {
	this.comboBox1 = new ComboBox();
	this.comboBox2 = new ComboBox();
	// 
	// comboBox1
	// 
	this.comboBox1.Location = new System.Drawing.Point(51, 157);
	this.comboBox1.Name = "comboBox1";
	this.comboBox1.Size = new System.Drawing.Size(121, 21);
	this.comboBox1.TabIndex = 0;
	this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged);
	// 
	// comboBox2
	// 
	this.comboBox2.Location = new System.Drawing.Point(51, 184);
	this.comboBox2.Name = "comboBox2";
	this.comboBox2.Size = new System.Drawing.Size(121, 21);
	this.comboBox2.TabIndex = 1;
	this.comboBox2.SelectedIndexChanged += new System.EventHandler(this.comboBox_SelectedIndexChanged);
	// 
	// Form1
	// 
	this.Controls.Add(this.comboBox2);
	this.Controls.Add(this.comboBox1);
}
  
private void comboBox_SelectedIndexChanged(Object sender, EventArgs e) {
	if (sender == this.comboBox1) {
		// Sender is comboBox1
	}
	else if (sender == this.comboBox2) {
		// Sender is comboBox2
	}
}


Then you can use the sender to distinguish the control that fired the event. The sender will be the ComboBox whose selected indexed changed regardless of how it changed (e.g. through code or through user interaction).

In the comboBox_SelectedIndexChanged() method, "this" refers to the Form because the method is defined in the Form class.

Take care,
Tom

-----------------------------------------------
Check out my blog at http://tjoe.wordpress.com

GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 3:07
JoeRip26-Sep-07 3:07 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
TJoe26-Sep-07 3:16
TJoe26-Sep-07 3:16 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 3:18
JoeRip26-Sep-07 3:18 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 3:21
JoeRip26-Sep-07 3:21 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
TJoe26-Sep-07 3:25
TJoe26-Sep-07 3:25 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
JoeRip26-Sep-07 3:34
JoeRip26-Sep-07 3:34 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
TJoe26-Sep-07 3:42
TJoe26-Sep-07 3:42 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
Luc Pattyn26-Sep-07 3:58
sitebuilderLuc Pattyn26-Sep-07 3:58 
GeneralRe: Who am I? Detecting the "current" control for a handler Pin
TJoe26-Sep-07 3:22
TJoe26-Sep-07 3:22 
QuestionHow to extract HTML code From any webpage using C#.Net Pin
allivelu26-Sep-07 1:35
allivelu26-Sep-07 1:35 
AnswerRe: How to extract HTML code From any webpage using C#.Net Pin
Christian Graus26-Sep-07 1:46
protectorChristian Graus26-Sep-07 1:46 
AnswerRe: How to extract HTML code From any webpage using C#.Net Pin
Matthew Cuba26-Sep-07 2:00
Matthew Cuba26-Sep-07 2:00 
QuestionSimulator Pin
prog_omer_esmail26-Sep-07 1:13
prog_omer_esmail26-Sep-07 1:13 
QuestionRe: Simulator Pin
ESTAN26-Sep-07 1:24
ESTAN26-Sep-07 1:24 
AnswerRe: Simulator Pin
pmarfleet26-Sep-07 1:47
pmarfleet26-Sep-07 1:47 
GeneralRe: Simulator Pin
PaulPrice26-Sep-07 1:55
PaulPrice26-Sep-07 1:55 
GeneralRe: Simulator Pin
ESTAN26-Sep-07 2:02
ESTAN26-Sep-07 2:02 

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.