简体   繁体   中英

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

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;
        
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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