2

我有这个按钮,在代码中创建,它有一个背景图像并且是透明的。到目前为止一切顺利,它可以工作,可怕的灰色背景颜色消失了。除了当我将鼠标悬停在它上面时,恼人的情绪不断出现。

所以我尝试了我能想到的,那就是添加一个事件监听器,它将在 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
        };
    }
4

1 回答 1

4

尝试添加这个:

nextBtn.FlatAppearance.MouseOverBackColor=Color.Transparent;
于 2013-11-07T19:03:56.670 回答