How do I pass variables to a buttons event method?

前端 未结 8 1817
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 08:29

I need to be able to pass along two objects to the method being fired when I click a button. How do I do this?

So far I\'ve been looking at creating a changed E

8条回答
  •  甜味超标
    2020-12-14 09:16

    You could use the Tag property of the button. You can add a string value to this property from the designer properties window and then pick it up within the handler as so:

        private void MyButton_Click(object sender, EventArgs e)
        {
            string tagValue = ((Button) sender).Tag;
    
            if(tag == "blah")
            {
                // Do something
            }
        }
    

提交回复
热议问题