70% Opacity Color to a Button WinForms

Question

I want to make that effect when I hover a button to still be like 30% transparent (so you can see the background image from the form) but still see some color..

I tried this but this just gives me a blank black:

private void roundedButton2_MouseEnter(object sender, EventArgs e)
        {
            roundedButton2.UseVisualStyleBackColor = false;
            roundedButton2.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, Color.Black);
        }

        private void roundedButton2_MouseLeave(object sender, EventArgs e)
        {
            roundedButton2.UseVisualStyleBackColor = true;
            roundedButton2.BackColor = Color.Transparent;
        }

Here I have the mouse out and mouse on the button so you can see what I have. EDIT: Solved it.... now the above code does exactly what I wanted.


Show source
| c#   | winforms   2016-12-17 23:12 1 Answers

Answers ( 1 )

  1. 2016-12-18 00:12

    Problem is solved. I changed the code as follows:

    private void roundedButton2_MouseEnter(object sender, EventArgs e)
            {
                roundedButton2.UseVisualStyleBackColor = false;
                roundedButton2.FlatAppearance.MouseOverBackColor = Color.FromArgb(100, Color.Black);
            }
    
            private void roundedButton2_MouseLeave(object sender, EventArgs e)
            {
                roundedButton2.UseVisualStyleBackColor = true;
                roundedButton2.BackColor = Color.Transparent;
            }
    

    Had to add FlatAppearance before the backcolor.

◀ Go back