Home > Enterprise >  MouseDown making something transparent
MouseDown making something transparent

Time:08-22

I am trying to make it so that when you hold your mouse down it will make the form transparent and when you take your mouse off it will make it go back to normal.

private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
                Form1.ActiveForm.Opacity = 90;
        }

CodePudding user response:

Here's a fairly complete sample of what you're trying to do. Does it help?

void Main()
{
    var f = new Form1();
    f.ShowDialog();
}

public class Form1 : Form
{
    public Form1()
    {
        this.MouseDown  = (s, e) => this.Opacity = 0.2;
        this.MouseUp  = (s, e) => this.Opacity = 1.0;
    }
}

It may help you to read the docs: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.form.opacity?view=windowsdesktop-6.0

Percentages are always to be read as the number divided by 100.0. So if you want 20% then you need 0.2.

  • Related