Reputation: 89
I made a custom button class in Visual Studio, and I would like to add an image to the constructor. The images are in the Properties/Resources of my project. Normally, I would add an image to my button like this:
btnBack.Image = Properties.Resources.back57;
In this scenario, back57 is the name of the image file.
This is the current constructor of my button class:
public MenuButton()
{
this.Font = new System.Drawing.Font("TrsNo__", 18);
this.Width = 160;
this.Height = 40;
this.FlatStyle = FlatStyle.Popup;
this.BackColor = System.Drawing.Color.DarkOrange;
this.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.MouseEnter += new System.EventHandler(mouseEnterCustom);
this.MouseLeave += new System.EventHandler(mouseLeaveCustom);
this.SetStyle(ControlStyles.Selectable, false);
}
How to edit the constructor so I can add image files from resources?
Edit 1: I assume it will look something like this.
public MenuButton(??????)
{
this.Image = ?????????
}
Upvotes: 0
Views: 357
Reputation: 596
add new cunstructor:
public MenuButton(Bitmap buttonImage)
: base()
{
this.Image = buttonImage
}
and create your button:
MenuButton menuBttn = new MenuButton(Properties.Resources.back57);
Upvotes: 2