Add similar behavior to a group of WinForms controls

后端 未结 1 1267
一个人的身影
一个人的身影 2021-01-28 14:34

I have a form with 6 buttons. These buttons serve to increase/decrease tha value of the respective textbox. Now I\'m trying to \"animate\" the buttons. I want to get another eff

相关标签:
1条回答
  • 2021-01-28 15:20

    if one effect should be applied for all buttons, try to add the same event handlers to them

    private void btn_MouseHover(object sender, EventArgs e)
    {
        (sender as Button).Image = Game_Helper.Properties.Resources.DownHover;
    }
    
    private void btn_MouseLeave(object sender, EventArgs e)
    {
        (sender as Button).Image = Game_Helper.Properties.Resources.Down;
    }
    

    button which raised event is available via sender variable

    this way you avoid code duplication for every button. creating a ButtonBehaviour or CustomButton is probably an over-engineering unless you need them in many forms

    0 讨论(0)
提交回复
热议问题