我试图创建一个不可见的可点击按钮,但是当我点击它时,没有任何反应......
我用来使按钮不可见的代码:
button1.Visible = false;
我想在点击按钮时显示图片(在它被隐藏之后)
答案 0 :(得分:6)
尝试使用此代替Invisible
属性:
button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderColor = BackColor;
button1.FlatAppearance.MouseOverBackColor = BackColor;
button1.FlatAppearance.MouseDownBackColor = BackColor;
答案 1 :(得分:3)
试试这个
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");
}
答案 2 :(得分:0)
首先从工具箱中拖动一个全新的按钮。离开属性列表而不是通过代码手动执行,更改以下设置应该可以获得所需的结果。
| Property | Settings |
---------------------------------------------------
| BackColor | Transparent |
| FlatStyle | Flat |
| FlatAppearance.MouseDownBackColor | Transparent |
| FlatAppearance.MouseOverBackColor | Transparent |
| ForeColor | Transparent |
| UseVisualStyleBackColor | False |
答案 3 :(得分:0)
一个对我有用的选项是我将其隐藏在另一个控件后面。
要在表单设计器中执行此操作:
答案 4 :(得分:0)
可以这么简单
button1.Opacity = 0;
为了更安全,添加类似这样的东西
button1.IsEnabled = false;