private void Form1_Load(object sender, EventArgs e) { // Adjust form Height = 200; Width = 100; // Create label and panel // No need for these to be private fields Label label = new Label { Text = @"Border clicked", Visible = false }; // Create panel Panel panel = new Panel { Height = 400, Width = 400, BackColor = Color.White, BackgroundImageLayout = ImageLayout.Stretch }; // Paint event handler. // Personally I prefer inline anonymous methods // over named methods when logic is simple // and it's not being reused panel.Paint += (o, args) => { // 'using' because we want to get rid of Graphics // and Pen when we are done drawing paths using (Graphics graphics = panel.CreateGraphics()) { using (Pen pen = new Pen(Color.Blue, 3)) { foreach (GraphicsPath path in _graphicsPaths) { graphics.DrawPath(pen, path); } } } }; // Mouse (down) event handler. panel.MouseDown += (o, args) => { // Get mouse point Point mousePoint = new Point(args.X, args.Y); // Again, we want to dispose Pen using (Pen pen = new Pen(Color.Transparent, 0F)) { // Get first path under mouse pointer GraphicsPath path = _graphicsPaths.FirstOrDefault(p => p.IsOutlineVisible(mousePoint, pen)); if (path == null) { return; } // If found, "flash" our informative label // in non-blocking way Task.Run(() => { label.Invoke((Action)(() => label.Visible = true)); Thread.Sleep(500); label.Invoke((Action)(() => label.Visible = false)); }); } }; // Add controls to containers panel.Controls.Add(label); Controls.Add(panel); }
private void ShopList_Load(object sender, EventArgs e) { string connectionString = @"Data Source = (LocalDB)\MSSQLLocalDB; AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True"; SqlConnection = new SqlConnection(connectionString); SqlCommand command = new SqlCommand("SELECT * FROM [ShopList]", SqlConnection); using (SqlConnection) { SqlConnection.Open(); SqlDataReader reader = command.ExecuteReader(); CheckBox[] cb = new CheckBox[50]; for (int j = 0; reader.Read(); j++) { l[j] = Int32.Parse(Convert.ToString(reader["IdResepy"])); cb[j] = new System.Windows.Forms.CheckBox(); cb[j].Location = new System.Drawing.Point(100, top); cb[j].Height = 40; cb[j].Width = 250; cb[j].Name = "cb" + (j).ToString(); cb[j].TextAlign = System.Drawing.ContentAlignment.MiddleLeft; cb[j].Text = Convert.ToString(reader["Name"]); Controls.Add(cb[j]); top += 40; Delet += 1; } top += 40; Button btn = new Button(); btn = new System.Windows.Forms.Button(); btn.Location = new System.Drawing.Point(100, top); btn.Height = 70; btn.Width = 450; btn.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; btn.Text = "Удалить рецепт из списка"; btn.Click += new System.EventHandler(Del); Controls.Add(btn); reader.Close(); } SqlConnection = new SqlConnection(connectionString); SqlCommand command1 = new SqlCommand("SELECT * FROM [ShopList]", SqlConnection); using (SqlConnection) { SqlConnection.Open(); SqlDataReader reader = command1.ExecuteReader(); top = top + 100; for (int j = 0; reader.Read(); j++) { CheckBox[] lb = new CheckBox[15]; for (int k = 0; k < lb.Length; k++) { lb[k] = null; lb[k] = new System.Windows.Forms.CheckBox(); lb[k].Location = new System.Drawing.Point(100, top); lb[k].Height = 40; lb[k].Width = 450; lb[k].Name = "lb" + (k).ToString(); lb[k].TextAlign = System.Drawing.ContentAlignment.MiddleLeft; if (!(Convert.ToString(reader["NameIng" + (k + 1)]) == "")) { if (!(float.Parse(Convert.ToString(reader["SumIng" + (k + 1)])) <= 0.01)) { lb[k].Text = Convert.ToString(reader["NameIng" + (k + 1)]) + " " + float.Parse(Convert.ToString(reader["SumIng" + (k + 1)])) + " " + Convert.ToString(reader["MeraIng" + (k + 1)]); Controls.Add(lb[k]); top += 40; } } } } } }