Suman Raj

Suman Raj

  • NA
  • 287
  • 13.7k

Add image to button using code in mdi form.

Sep 21 2018 1:17 AM
public void AddMenu()
{
Menus.Add("Database");
Menus.Add("Setting");
Menus.Add("Measure");
Menus.Add("Help");
Menus.Add("About");
int width, height;
width = 60;
height = 60;
int top = 10;
int left = 10;

for (int i = 1; i < Menus.Count; i++)
{
Button button = new Button();
button.Left = left;
button.Top = top;
button.Text = Menus[i];
this.Controls.Add(button);
button.BackColor = Color.RosyBrown;
button.BringToFront();
button.Size = new Size(width, height);
left += button.Height + 25;
button.ImageAlign = ContentAlignment.MiddleCenter;
}
}
//i need to add image for each list item.
example if i add list[1] item then i need to add png  image for the button having same list[1] item name which i already added to project by created a resource folder that having images.
Thanks.
 

Answers (1)