Goran Bibic

Goran Bibic

  • 480
  • 2.9k
  • 200.7k

Create rounded button?

Apr 9 2018 1:13 AM
Rounded button?
 Existing code is ok
  1. private void Form1_Load(object sender, EventArgs e)  
  2.        {  
  3.            // TODO: This line of code loads data into the 'bssDataSet.roba_usluge' table. You can move, or remove it, as needed.  
  4.            this.roba_uslugeTableAdapter.Fill(this.bssDataSet.roba_usluge);  
  5.   
  6.   
  7.   
  8.            SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True");  
  9.           
  10.            SqlCommand cmd = new SqlCommand("SELECT ime+'-'+cijena_sa_porezom, data FROM roba_usluge", con);  
  11.   
  12.            // Getting all the data to ItemTable        
  13.            var da = new SqlDataAdapter(cmd);  
  14.            var ItemTable = new DataTable();  
  15.            da.Fill(ItemTable);  
  16.   
  17.            con.Open();  
  18.            Int32 count = ItemTable.Rows.Count;  
  19.            con.Close();  
  20.   
  21.            int top = 50;  
  22.            int left = 50;  
  23.            for (int i = 1; i <= count; i++)  
  24.            // for (int i = 0; i < count; i++)      
  25.            {  
  26.                Button button = new Button();  
  27.                button.Size = new Size(128,128);  
  28.                button.BackColor = Color.Transparent;  
  29.                //button.FlatStyle = FlatStyle.Flat;  
  30.                button.FlatAppearance.BorderSize = 0;  
  31.                button.Font = new System.Drawing.Font("Trebuchet MS", 10);  
  32.                button.TextAlign = ContentAlignment.TopCenter;  
  33.                button.BackgroundImageLayout = ImageLayout.Zoom;  
  34.                  
  35.                button.Left = left;  
  36.                button.Top = top;  
  37.                button.Text = ItemTable.Rows[i - 1][0].ToString();  
  38.                
  39.                    if (ItemTable.Rows[i - 1][1] != null)  
  40.                    {  
  41.                    try  
  42.                    {  
  43.                        byte[] _byte = (byte[])ItemTable.Rows[i - 1][1];  
  44.                        MemoryStream ms = new MemoryStream(_byte);  
  45.                        button.BackgroundImage = System.Drawing.Image.FromStream(ms); 
  46.                    }  
  47.                    catch { }  
  48.                }  
  49.              
  50.   
  51.                button.Click += new EventHandler(this.btn_Click);  
  52.   
  53.   
  54.                this.Controls.Add(button);  
  55.                if (i % 5 == 0)  
  56.                {  
  57.                    left = 50;  
  58.                    top += button.Height + 2;  
  59.                }  
  60.                else  
  61.                {  
  62.                    left += button.Width + 2;  
  63.                }  
  64.              
  65.   
  66.   
  67.            }  
  68.        } 
 

Answers (11)