| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 | 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);        }    }}
 |