hi friends i have a windows form where i am generating buttons dynamically reading a xml file which contains image , store id etc.
now i want to show the image in the button control, but when i am setting the image property for the button its does not fit on the button perfectly as the image size is very big. so finally i want to fit the image completely on the button.
i am trying the following code.
private void BusinessTemplateForm_Load(object sender, EventArgs e)
{
BtnBack.Visible = false;
BtnNext.Visible = false;
string path = "D:\\Myfiles\\";
String[] filePaths = Directory.GetFiles(@"D:\Myfiles\", "*.xml").Select(fileName => Path.GetFileName(fileName)).ToArray();
foreach (string str in filePaths)
{
XDocument XmlDoc;
XmlDoc = XDocument.Load(path+str);
ClassBusiness mybusiness = new ClassBusiness();
XElement BusinessTemplate_element = XmlDoc.Root.Element("BusinessTemplate");
foreach (XElement element in BusinessTemplate_element.Elements())
{
if (element.Name.ToString().Equals("storeId"))
{
mybusiness.storeid = element.Value;
}
if (element.Name.ToString().Equals("terminalId"))
{
mybusiness.terminamid = element.Value;
}
if (element.Name.ToString().Equals("templateImage"))
{
mybusiness.image = element.Value;
}
}
Button btn = new Button();
btn.Text = mybusiness.terminamid;
btn.Width = 100;
btn.Height = 100;
btn.Click += new EventHandler(btn_click);
byte[] array = Convert.FromBase64String(mybusiness.image);
btn.Image = byteArrayToImage(array);
flowLayoutPanel1.Controls.Add(btn);
}
}
public Image byteArrayToImage(byte[] byteArrayIn)
{
Image returnImage = null;
try
{
MemoryStream ms = new MemoryStream(byteArrayIn);
returnImage = Image.FromStream(ms);
}
catch (Exception ex)
{
}
return returnImage;
}
protected void btn_click(object sender, EventArgs e)
{
Button buttonHandler = (sender as Button);
SystemSettingsform systemform = new SystemSettingsform();
systemform.Show();
this.Dispose();
}