c# button control
-
hello, i'm working on a .NET windows form. i have programmatically created a column of buttons using the following code: for (int j = 0; j < farmData.Tables["plate"].Rows.Count; j++) { Button viewBtn = new Button(); viewBtn.Text = "View"; viewBtn.Name = "viewBtn" + j.ToString(); viewBtn.UseVisualStyleBackColor = true; viewBtn.Click += new System.EventHandler(this.viewBtn_Click); tbl.Controls.Add(viewBtn, 0, j + 2); } when i push a button, and the viewBtn_Click method is called, how do i get the button name so that i know exactly which button was pushed? Thanks in adavance for any insight! RC
-
hello, i'm working on a .NET windows form. i have programmatically created a column of buttons using the following code: for (int j = 0; j < farmData.Tables["plate"].Rows.Count; j++) { Button viewBtn = new Button(); viewBtn.Text = "View"; viewBtn.Name = "viewBtn" + j.ToString(); viewBtn.UseVisualStyleBackColor = true; viewBtn.Click += new System.EventHandler(this.viewBtn_Click); tbl.Controls.Add(viewBtn, 0, j + 2); } when i push a button, and the viewBtn_Click method is called, how do i get the button name so that i know exactly which button was pushed? Thanks in adavance for any insight! RC
-
You should be able to cast the
sender
parameter toButton
type:Button button = (Button)sender;
regards