From 5ff2f7cce80fd15ae045bdcdd527f6715e8dd12e Mon Sep 17 00:00:00 2001 From: ElEgEv <112943269+ElEgEv@users.noreply.github.com> Date: Wed, 27 Sep 2023 13:52:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AF=20=D0=A1=D0=94=D0=90=D0=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../VisualComponentsForm/FormMain.cs | 18 ++++++---- .../Components/ComponentWord.Designer.cs | 36 +++++++++++++++++++ .../Components/ComponentWord.cs | 25 +++++++++++++ VisualComponentsLib/MyDataGridView.cs | 14 ++++---- VisualComponentsLib/MyTextBox.cs | 7 ++-- .../SupportClass/DataGridViewInfoCol.cs | 27 ++++++++++++++ 6 files changed, 109 insertions(+), 18 deletions(-) create mode 100644 VisualComponentsLib/Components/ComponentWord.Designer.cs create mode 100644 VisualComponentsLib/Components/ComponentWord.cs create mode 100644 VisualComponentsLib/SupportClass/DataGridViewInfoCol.cs diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.cs b/VisualComponentsForm/VisualComponentsForm/FormMain.cs index 4cde63e..6c1e60c 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.cs @@ -1,18 +1,16 @@ using VisualComponentsForm.Models; +using VisualComponentsLib.SupportClass; namespace VisualComponentsForm { public partial class FormMain : Form { - private int countCol = 4; private int numberObject; - private List nameCol = new List { "", "", "", "" }; - private List widthCol = new List { 60, 60, 60, 60 }; - private List showCol = new List { true, true, true, true }; - private List nameField = new List { "Id", "Name", "Surname", "Age" }; private List peoples; + private List info; + public FormMain() { numberObject = 0; @@ -25,6 +23,14 @@ namespace VisualComponentsForm new People(3, "", "", 23) }; + info = new List + { + new DataGridViewInfoCol("", "Id", 60, true), + new DataGridViewInfoCol("", "Name", 60, true), + new DataGridViewInfoCol("", "Surname", 60, true), + new DataGridViewInfoCol("", "Age", 60, true) + }; + InitializeComponent(); } @@ -63,7 +69,7 @@ namespace VisualComponentsForm private void ButtonCreateColumns_Click(object sender, EventArgs e) { - myDataGridView.AddHeader(countCol, nameCol, widthCol, showCol, nameField); + myDataGridView.AddHeader(info); } private void ButtonClearTable_Click(object sender, EventArgs e) diff --git a/VisualComponentsLib/Components/ComponentWord.Designer.cs b/VisualComponentsLib/Components/ComponentWord.Designer.cs new file mode 100644 index 0000000..b4654d6 --- /dev/null +++ b/VisualComponentsLib/Components/ComponentWord.Designer.cs @@ -0,0 +1,36 @@ +namespace VisualComponentsLib.Components +{ + partial class ComponentWord + { + /// + /// Обязательная переменная конструктора. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Освободить все используемые ресурсы. + /// + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Код, автоматически созданный конструктором компонентов + + /// + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. + /// + private void InitializeComponent() + { + components = new System.ComponentModel.Container(); + } + + #endregion + } +} diff --git a/VisualComponentsLib/Components/ComponentWord.cs b/VisualComponentsLib/Components/ComponentWord.cs new file mode 100644 index 0000000..13df31c --- /dev/null +++ b/VisualComponentsLib/Components/ComponentWord.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VisualComponentsLib.Components +{ + public partial class ComponentWord : Component + { + public ComponentWord() + { + InitializeComponent(); + } + + public ComponentWord(IContainer container) + { + container.Add(this); + + InitializeComponent(); + } + } +} diff --git a/VisualComponentsLib/MyDataGridView.cs b/VisualComponentsLib/MyDataGridView.cs index 30fc42c..e1b2124 100644 --- a/VisualComponentsLib/MyDataGridView.cs +++ b/VisualComponentsLib/MyDataGridView.cs @@ -8,6 +8,7 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using VisualComponentsLib.SupportClass; namespace VisualComponentsLib { @@ -41,17 +42,16 @@ namespace VisualComponentsLib } //публичный метод создания заголовков таблицы - public void AddHeader(int countCol, List nameCol, List widthCol, - List showCol, List nameField) + public void AddHeader(List elements) { - for (int i = 0; i < countCol; i++) + foreach (var elem in elements) { DataGridViewColumn textColumn = new DataGridViewColumn(); - textColumn.Name = nameField[i]; - textColumn.HeaderText = nameCol[i]; - textColumn.Width = widthCol[i]; - textColumn.Visible = showCol[i]; + textColumn.Name = elem.HeaderName; + textColumn.HeaderText = elem.Name; + textColumn.Width = elem.Width; + textColumn.Visible = elem.IsVisible; textColumn.CellTemplate = new DataGridViewTextBoxCell(); dataGridView.Columns.Add(textColumn); diff --git a/VisualComponentsLib/MyTextBox.cs b/VisualComponentsLib/MyTextBox.cs index d2de0b9..e79fd70 100644 --- a/VisualComponentsLib/MyTextBox.cs +++ b/VisualComponentsLib/MyTextBox.cs @@ -33,12 +33,9 @@ namespace VisualComponentsLib set { - if(!CheckValue()) - { - textBox.Text = null; - } + checkBox.Checked = !value.HasValue; - textBox.Text = value.ToString(); + textBox.Text = value?.ToString(); } } diff --git a/VisualComponentsLib/SupportClass/DataGridViewInfoCol.cs b/VisualComponentsLib/SupportClass/DataGridViewInfoCol.cs new file mode 100644 index 0000000..8db38c4 --- /dev/null +++ b/VisualComponentsLib/SupportClass/DataGridViewInfoCol.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VisualComponentsLib.SupportClass +{ + public class DataGridViewInfoCol + { + public string Name { get; set; } + + public string HeaderName { get; set; } + + public int Width { get; set; } + + public bool IsVisible { get; set; } + + public DataGridViewInfoCol(string name, string headerName, int width, bool isVisible) + { + Name = name; + HeaderName = headerName; + Width = width; + IsVisible = isVisible; + } + } +}