我尝试创建一个不可见的可点击按钮,但是当我点击它时,没有任何反应......
我用来使按钮不可见的代码:
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 |
对我有用的一个选项是我只是将其隐藏在另一个控件后面。
要在表单设计器中执行此操作:
可以这么简单
button1.Opacity = 0;
为了更安全,添加这样的内容
button1.IsEnabled = false;
Button button1 = new Button();
button1.Text = "&t"; // Ampersand followed by a letter
button1.Size = new Size(0, 0);
button1.UseMnemonic = true;
现在按钮不可见,可以通过按 Alt + T 激活