Register MouseEnter/MouseLeave events for disabled controls in windows form?

后端 未结 5 1378
暗喜
暗喜 2021-01-13 14:43

I want to register MouseEnter/MouseLeave events for disabled buttons. It does not work allthough it does work for enabled buttons..

//Enable Disable controls         


        
5条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-13 15:17

    yes , when you disable button , events will disable.

    you can use this trick:

    put your button in panel1 , enter image description here

    then use the same event of button for panel1. like this:

        btns.MouseEnter += new EventHandler(btns_MouseEnter);
        btns.MouseLeave += new EventHandler(btns_MouseLeave);
    
        panel1.MouseEnter += new System.EventHandler(btns_MouseEnter);
        panel1.MouseLeave += new System.EventHandler(btns_MouseLeave);
    

    it will work.

提交回复
热议问题