using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Пример_плиточного_интерфейса { public partial class Form1 : Form { class Furnitura : Panel { public System.Windows.Forms.Label LblCount; public System.Windows.Forms.Label LblName; public System.Windows.Forms.PictureBox PbxPhoto; public string ID; // ID фурнитуры public Furnitura() { this.PbxPhoto = new System.Windows.Forms.PictureBox(); this.LblName = new System.Windows.Forms.Label(); this.LblCount = new System.Windows.Forms.Label(); // // panel1 // this.BackColor = System.Drawing.Color.White; this.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.Controls.Add(this.LblCount); this.Controls.Add(this.LblName); this.Controls.Add(this.PbxPhoto); this.Location = new System.Drawing.Point(45, 43); this.Name = "panel1"; this.Size = new System.Drawing.Size(182, 175); this.TabIndex = 0; // // PbxPhoto // this.PbxPhoto.Location = new System.Drawing.Point(38, 21); this.PbxPhoto.Name = "PbxPhoto"; this.PbxPhoto.Size = new System.Drawing.Size(100, 86); this.PbxPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom; this.PbxPhoto.TabIndex = 0; this.PbxPhoto.TabStop = false; // // LblName // this.LblName.AutoSize = true; this.LblName.Location = new System.Drawing.Point(15, 114); this.LblName.Name = "LblName"; this.LblName.Size = new System.Drawing.Size(44, 16); this.LblName.TabIndex = 1; this.LblName.Text = "label1"; // // LblCount // this.LblCount.AutoSize = true; this.LblCount.Location = new System.Drawing.Point(15, 140); this.LblCount.Name = "LblCount"; this.LblCount.Size = new System.Drawing.Size(44, 16); this.LblCount.TabIndex = 2; this.LblCount.Text = "label2"; } } public Form1() { InitializeComponent(); } string TxtCon = @"Data Source=213.155.192.79,3002;Initial Catalog=fab2022;Persist Security Info=True;User ID=mil;Password=mil"; Furnitura CurrentFur; // текущая выделенная плитка void FillPanel() { SqlConnection Con = new SqlConnection(TxtCon); Con.Open(); SqlCommand Query = new SqlCommand("select * from Furnitura", Con); SqlDataReader Res = Query.ExecuteReader(); flowLayoutPanel1.Controls.Clear(); while(Res.Read()) { Furnitura ItemFur = new Furnitura(); ItemFur.LblName.Text = "Название: " + Res["namefur"]; ItemFur.LblCount.Text = "Кол-во на складе: " + Res["countfur"]; try { ItemFur.PbxPhoto.Image = Image.FromFile(Application.StartupPath + "\\Фурнитуры\\" + Res["photo"]); } catch { ItemFur.PbxPhoto.Image = Image.FromFile(Application.StartupPath + "\\Фурнитуры\\picture.png"); } ItemFur.ID = Res["idfur"].ToString(); ItemFur.Click += ItemFur_Click; ItemFur.PbxPhoto.Click += Object_Click; ItemFur.LblCount.Click += Object_Click; ItemFur.LblName.Click += Object_Click; flowLayoutPanel1.Controls.Add(ItemFur); // если добавилась первая плитка, то сделать ее выделенной if (flowLayoutPanel1.Controls.Count == 1) { CurrentFur = ItemFur; CurrentFur.BackColor = Color.LightGreen; LblID.Text = CurrentFur.ID; } } Con.Close(); } private void Object_Click(object sender, EventArgs e) { CurrentFur.BackColor = Color.White; CurrentFur = (sender as Control).Parent as Furnitura; CurrentFur.BackColor = Color.LightGreen; LblID.Text = CurrentFur.ID; } private void ItemFur_Click(object sender, EventArgs e) { CurrentFur.BackColor = Color.White; CurrentFur = sender as Furnitura; CurrentFur.BackColor = Color.LightGreen; LblID.Text = CurrentFur.ID; } private void Form1_Load(object sender, EventArgs e) { FillPanel(); } private void button1_Click(object sender, EventArgs e) { MessageBox.Show("ID выбранной фурнитуры: " + CurrentFur.ID); } } }