Goran Bibic

Goran Bibic

  • 480
  • 2.9k
  • 200.7k

Create rounded button c#

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

Answers (3)