鼠标悬停上的C#按钮透明背景

时间:2013-11-07 18:56:59

标签: c# button

我有这个按钮,在代码中创建,具有背景图像并且是透明的。到目前为止这么好,它的工作原理,可怕的灰色背景颜色消失了。 除了当我将鼠标悬停在它上面时,刺激性不断回来。

所以我尝试了我能想到的,并且添加了一个eventlistener,它可以在MouseHover,Enter和Leave上将背景颜色更改为透明。但似乎没有任何效果。

有什么想法吗?

到目前为止,这是我的代码:

    private void CreateFirstScreen() {
        mainForm.BackgroundImage = Image.FromFile(@"[img dir]");

        Button nextBtn = new Button();
        nextBtn.BackColor = Color.Transparent;        <== this works!
        nextBtn.BackgroundImage = Image.FromFile(@"[img dir]");
        nextBtn.FlatStyle = FlatStyle.Flat;

        nextBtn.FlatAppearance.BorderSize = 0;
        nextBtn.SetBounds(1555, 820, 274, 106);

        mainForm.Controls.Add(nextBtn);


        nextBtn.MouseHover += (sender, args) => {
            nextBtn.BackColor = Color.Transparent;    <= doesn't work
        };
        nextBtn.MouseEnter += (sender, args) => {
            nextBtn.BackColor = Color.Transparent;    <= doesn't work
        };
        nextBtn.MouseLeave += (sender, args) => {
            nextBtn.BackColor = Color.Transparent;    <= doesn't work
        };
        nextBtn.Click += (sender, args) => {
            CreateSecondScreen();                     <= does work
            mainForm.Controls.Remove(nextBtn);        <= does work
        };
    }

1 个答案:

答案 0 :(得分:2)

尝试添加此内容:

nextBtn.FlatAppearance.MouseOverBackColor=Color.Transparent;