Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Need to set smaller size image in button
Need to setup

picture
label
label

In same button
With my code text is over picture
Need to add some frame or something for picture
Winforms
Thank you

What I have tried:

private void TopliNapitciButton_Click(object sender, EventArgs e)
       {
           panel1.Controls.Clear();

           string conString = ConnectionClass.PullData(labelgodina.Text);
           SqlConnection con = new SqlConnection(conString);
           SqlCommand cmd = new SqlCommand("SELECT naziv+' - '+CAST(FORMAT(cijena_sa_porezom, 'N2') AS varchar), data FROM dbo.roba_usluge where grupa_artikala='Napitci' and status='Aktivan'", con);

           var da = new SqlDataAdapter(cmd);
           var ItemTable = new DataTable();
           da.Fill(ItemTable);

           con.Open();
           Int32 count = ItemTable.Rows.Count;
           con.Close();

           int top = 190;
           int left = 5;
           for (int i = 1; i <= count; i++)
           {
               Button button = new Button();
               button.Size = new Size(128, 128);
               button.BackColor = Color.Transparent;
               //button.FlatStyle = FlatStyle.Flat;
               button.FlatAppearance.BorderSize = 0;
               button.Font = new System.Drawing.Font("Trebuchet MS", 10);
               button.TextAlign = ContentAlignment.BottomCenter;
               button.BackgroundImageLayout = ImageLayout.Zoom;

               button.Left = left;
               button.Top = top;
               button.Text = ItemTable.Rows[i - 1][0].ToString();

               if (ItemTable.Rows[i - 1][1] != null)
               {
                   try
                   {
                       byte[] _byte = (byte[])ItemTable.Rows[i - 1][1];
                       MemoryStream ms = new MemoryStream(_byte);
                       button.BackgroundImage = System.Drawing.Image.FromStream(ms);//bilo image
                   }
                   catch { }
               }

               button.Click += new EventHandler(this.btn_Click);

               panel1.Controls.Add(button);

               if (i % 4 == 0)
               {
                   left = 5;
                   top += button.Height + 2;
               }
               else
               {
                   left += button.Width + 2;
               }
           }
       }
Posted
Updated 27-Mar-24 9:07am
v2
Comments
Jo_vb.net 27-Mar-24 15:06pm    
Is your project WPF or WinForms or what else?
Stylus STYLUS 27-Mar-24 15:06pm    
Sorry, winforms

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900