Goran Bibic

Goran Bibic

  • 454
  • 2.9k
  • 177.9k

Clear private void with click C#

May 25 2018 11:14 AM
My code work and create automatcly buttons...

Everything working fine

I need clear form on button click

some help?
 
  1. private void artikli_buttoni()  //pice  
  2.        {  
  3.   
  4.            SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=bss;Integrated Security=True");  
  5.            //SqlConnection con = new SqlConnection(cs);  
  6.            SqlCommand cmd = new SqlCommand("SELECT ime+'-'+cijena_sa_porezom, data FROM roba_usluge where grupa_artikala='Pice'", con);  
  7.   
  8.   
  9.            var da = new SqlDataAdapter(cmd);  
  10.            var ItemTable = new DataTable();  
  11.            da.Fill(ItemTable);  
  12.   
  13.            con.Open();  
  14.            Int32 count = ItemTable.Rows.Count;  
  15.            con.Close();  
  16.   
  17.            int top = 70;  
  18.            int left = 10;  
  19.            for (int i = 1; i <= count; i++)  
  20.   
  21.            {  
  22.                Button button = new Button();  
  23.                button.Size = new Size(128, 128);  
  24.                button.BackColor = Color.Transparent;  
  25.                //button.FlatStyle = FlatStyle.Flat;  
  26.                button.FlatAppearance.BorderSize = 0;  
  27.                button.Font = new System.Drawing.Font("Trebuchet MS", 10);  
  28.                button.TextAlign = ContentAlignment.TopCenter;  
  29.                button.BackgroundImageLayout = ImageLayout.Zoom;  
  30.   
  31.                button.Left = left;  
  32.                button.Top = top;  
  33.                button.Text = ItemTable.Rows[i - 1][0].ToString();  
  34.   
  35.                if (ItemTable.Rows[i - 1][1] != null)  
  36.                {  
  37.                    try  
  38.                    {  
  39.                        byte[] _byte = (byte[])ItemTable.Rows[i - 1][1];  
  40.                        MemoryStream ms = new MemoryStream(_byte);  
  41.                        button.BackgroundImage = System.Drawing.Image.FromStream(ms);//bilo image  
  42.                    }  
  43.                    catch { }  
  44.                }  
  45.   
  46.   
  47.                button.Click += new EventHandler(this.btn_Click);  
  48.   
  49.   
  50.                this.Controls.Add(button);  
  51.                if (i % 5 == 0)  
  52.                {  
  53.                    left = 10;  
  54.                    top += button.Height + 2;  
  55.                }  
  56.                else  
  57.                {  
  58.                    left += button.Width + 2;  
  59.                }  
  60.   
  61.   
  62.   
  63.            }  
  64.        } 
 

Answers (8)