简体   繁体   English

在 C# windows 应用程序窗体中按住它的同时更改按钮设计

[英]Changing button design while holding it in C# windows application form

I want to design a button in which when I hold it it will change the style of a button.我想设计一个按钮,当我按住它时,它会改变按钮的样式。 Like the current button-style is square with no border but when I hold it by mouse it will change the style of a button from square to round or 3d square but when I leave that button it will change back to my original style就像当前的按钮样式是没有边框的方形,但是当我用鼠标按住它时,它会将按钮的样式从方形更改为圆形或 3d 方形,但是当我离开该按钮时,它将变回我原来的样式

This is what I tried:这是我尝试过的:

 private void btnfeeder2_MouseDown(object sender, MouseEventArgs e)
            {
                Button btnfeeder2 = sender as Button;
                if (btnfeeder2 != null)
                {
                btnfeeder2.FlatStyle = (btnfeeder2.FlatStyle == FlatStyle.Standard) ? FlatStyle.System : FlatStyle.Standard;
                }
            }

as result: it does change the button style but not by holding it but by pressing it and it stays even if I leave the button.结果:它确实改变了按钮样式,但不是通过按住它而是通过按下它,即使我离开按钮它也会保持不变。 I have to click the button again to go back to my original style.我必须再次单击该按钮才能回到我原来的风格。

For verification, I changed the default back color to red.为了验证,我将默认背景颜色更改为红色。


    private void btnfeeder2_MouseDown(object sender, MouseEventArgs e)
    {
        
            btnfeeder2.FlatStyle = (btnfeeder2.FlatStyle == FlatStyle.Standard) ? FlatStyle.System : FlatStyle.Standard;
            btnfeeder2.BackColor = Color.White;
      
    }
    
    private void btnfeeder2_MouseUp(object sender, MouseEventArgs e)
    {
      
            btnfeeder2.FlatStyle = FlatStyle.Flat;
            btnfeeder2.BackColor = Color.Red;
        
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM