创建隐形可点击按钮

问题描述 投票:0回答:6

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

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

button1.Visible = false;

我想在单击按钮时显示图片(在将其设为不可见之后)

c# visual-studio button
6个回答
7
投票

尝试这个而不是

Invisible
属性:

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

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");
    }

0
投票

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

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

0
投票

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

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

  1. 将要隐藏的按钮放在表单上的任何位置(放在较大的多行文本框上效果很好)。
  2. 右键单击按钮。
  3. 单击“发送到后台”选项。

0
投票

可以这么简单

button1.Opacity = 0;

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

button1.IsEnabled = false;

0
投票
Button button1 = new Button();
button1.Text = "&t"; // Ampersand followed by a letter
button1.Size = new Size(0, 0); 
button1.UseMnemonic = true;

现在按钮不可见,可以通过按 Alt + T 激活

© www.soinside.com 2019 - 2024. All rights reserved.