Reputation: 59
I've tried to create an invisible clickable button, but when I click it, nothing happens...
The code I used to make the button invisible:
button1.Visible = false;
I want to show a picture when the button is clicked (after it's been made invisible)
Upvotes: 4
Views: 18571
Reputation: 1
Button button1 = new Button();
button1.Text = "&t"; // Ampersand followed by a letter
button1.Size = new Size(0, 0);
button1.UseMnemonic = true;
Now the button is invisible and can be activated by pressing Alt + T
Upvotes: 0
Reputation: 59
can be simple like that
button1.Opacity = 0;
For more security, add something like this
button1.IsEnabled = false;
Upvotes: 0
Reputation: 14256
An option that worked for me is I just hid it behind another control.
To do this in the Form Designer:
Upvotes: 0
Reputation: 245
Begin by dragging in a brand new button from the toolbox. Going off the property list instead of doing it manually through code, changing the following settings should get you the desired result.
| Property | Settings |
---------------------------------------------------
| BackColor | Transparent |
| FlatStyle | Flat |
| FlatAppearance.MouseDownBackColor | Transparent |
| FlatAppearance.MouseOverBackColor | Transparent |
| ForeColor | Transparent |
| UseVisualStyleBackColor | False |
Upvotes: 0
Reputation: 5990
Try this
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");
}
Upvotes: 3
Reputation: 3476
Try this instead of Invisible
property:
button1.FlatStyle = FlatStyle.Flat;
button1.FlatAppearance.BorderColor = BackColor;
button1.FlatAppearance.MouseOverBackColor = BackColor;
button1.FlatAppearance.MouseDownBackColor = BackColor;
Upvotes: 7