创建不可见的可点击按钮

Create invisible clickable button

我试图创建一个不可见的可点击按钮,但是当我点击它时,没有任何反应...

我用来使按钮不可见的代码:

button1.Visible = false;

我想在点击按钮时显示图片(在它被设置为不可见之后)

试试这个而不是 Invisible 属性:

button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderColor = BackColor;
button1.FlatAppearance.MouseOverBackColor = BackColor;
button1.FlatAppearance.MouseDownBackColor = BackColor;

试试这个

 private void CreateButton()
    {
        button1 = new Button();
        button1.FlatAppearance.BorderSize = 0;
        button1.FlatAppearance.MouseDownBackColor = Color.Transparent;
        button1.FlatAppearance.MouseOverBackColor = Color.Transparent;
        button1.FlatStyle = FlatStyle.Flat;
        button1.ForeColor = BackColor;
        button1.Location = new Point(197, 226); //Give your own location as needed
        button1.Name = "button1";
        button1.Size = new Size(75, 23);
        button1.TabIndex = 0;
        button1.Text = "button1";
        button1.UseVisualStyleBackColor = true;
        button1.Click += this.button1_Click;
        Controls.Add(button1);
    }
    private void button1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("clicked");
    }

首先从工具箱中拖入一个全新的按钮。离开 属性 列表而不是通过代码手动执行,更改以下设置应该可以获得所需的结果。

| Property                          | Settings    |
---------------------------------------------------
| BackColor                         | Transparent |
| FlatStyle                         | Flat        |
| FlatAppearance.MouseDownBackColor | Transparent |
| FlatAppearance.MouseOverBackColor | Transparent |
| ForeColor                         | Transparent |
| UseVisualStyleBackColor           | False       |

一个对我有用的选项是我只是将它隐藏在另一个控件后面。

要在表单设计器中执行此操作:

  1. 将要隐藏的按钮放在表单的任意位置(在较大的多行文本框上效果很好)。
  2. 右击按钮。
  3. 单击 "Send to Back."
  4. 的选项

可以这么简单

button1.Opacity = 0;

为了更安全,添加类似这样的内容

button1.IsEnabled = false;