I need to use a .png file as a button . I just want to show a picture ( without any extra area around it ) to users .
My problem is in design and specify the area that should reacts clicking . I changed some properties of my button , but I couldn't achieve to my purpose . I changed the FlatStyle to Flat or the BackColor to Transparent , but the button has a colored background around itself yet . I need to remove the background completely .
I also tried the PictureBox , but I couldn't remove the background by properties again .
Windows. Forms namespace. Step 2: Drag the Button control from the ToolBox and drop it on the windows form. You are allowed to place a Button control anywhere on the windows form according to your need.
create an image. set the source of the image to the right file of your resources (e.g. a . png file that you included to your project) drag the image over the button. A text shows that asks you to press ALT to replace the text of the button with the image.
Use a Button
instead of a PictureBox
. because it also gives the ability to use keyboard and tabbing, but the PictureBox
does not.
Add a Button
to your form and set these properties:
Image = optionalPNGImage //should be 32bpp (alpha channel enabled)
BackColor = Color.Transparent;
FlatStyle = FlatStyle.Flat;
FlatAppearance.BorderSize = 0;
FlatAppearance.MouseDownBackColor = Color.Transparent;
FlatAppearance.MouseOverBackColor = Color.Transparent;
ForeColor = System.Drawing.Color.White;
Text = "Hello";
The result would be like this:
Next, if you want to change the picture of the Button
on mouse over or mouse click, create these events:
//happens when your mouse enters the region of the button.
private void button1_MouseEnter(object sender, EventArgs e)
{
button1.Image = picMouseOver;
}
//happens when your mouse leaves the region of the button.
private void button1_MouseLeave(object sender, EventArgs e)
{
button1.Image = picRegular;
}
//happens when your mouse button is down inside the region of the button.
private void button1_MouseDown(object sender, MouseEventArgs e)
{
button1.Image = picMouseDown;
}
//happens when your mouse button goes up after it went down.
private void button1_MouseUp(object sender, MouseEventArgs e)
{
button1.Image = picRegular;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With