From 7204b0c1c9dc9381500ba90ffad2f70ceb50026f Mon Sep 17 00:00:00 2001 From: Marselchi Date: Fri, 6 Sep 2024 10:48:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B0=D0=BD=D0=BE=20=D0=B9=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Attributes/AlwaysCreateAttribute.cs | 4 +- COP/CustomComponents/CustomCheckedListBox.cs | 4 +- COP/CustomComponents/CustomTreeView.cs | 9 +-- COP/WinFormsTestApp/Form1.Designer.cs | 79 ++++++++++++++++++- COP/WinFormsTestApp/Form1.cs | 22 +++++- COP/WinFormsTestApp/TestClasses/Someone.cs | 1 + 6 files changed, 104 insertions(+), 15 deletions(-) diff --git a/COP/CustomComponents/Attributes/AlwaysCreateAttribute.cs b/COP/CustomComponents/Attributes/AlwaysCreateAttribute.cs index 7a68162..4b900b5 100644 --- a/COP/CustomComponents/Attributes/AlwaysCreateAttribute.cs +++ b/COP/CustomComponents/Attributes/AlwaysCreateAttribute.cs @@ -8,9 +8,7 @@ namespace CustomComponents.Attributes { public class AlwaysCreateAttribute : Attribute { - public bool IsAlwaysCreate { get; } - public AlwaysCreateAttribute() - { IsAlwaysCreate = true; } + { } } } diff --git a/COP/CustomComponents/CustomCheckedListBox.cs b/COP/CustomComponents/CustomCheckedListBox.cs index 91e395c..ea371bb 100644 --- a/COP/CustomComponents/CustomCheckedListBox.cs +++ b/COP/CustomComponents/CustomCheckedListBox.cs @@ -33,11 +33,13 @@ namespace CustomComponents } set { - if (!checkedListBox.Items.Contains(value)) + int index = checkedListBox.Items.IndexOf(value); + if (index == -1) { return; } checkedListBox.SelectedItem = value; + checkedListBox.SetItemChecked(index, true); } } diff --git a/COP/CustomComponents/CustomTreeView.cs b/COP/CustomComponents/CustomTreeView.cs index f2c8797..45029d2 100644 --- a/COP/CustomComponents/CustomTreeView.cs +++ b/COP/CustomComponents/CustomTreeView.cs @@ -68,7 +68,7 @@ namespace CustomComponents private Dictionary _getValuesWithStructure(T obj, string propertyName) { - PropertyInfo[]? properties = obj!.GetType().GetProperties(); + PropertyInfo[]? properties = obj?.GetType().GetProperties(); var dict = new Dictionary(); // Получаем все значения свойств в структурированном виде (относительно иерархии) @@ -82,12 +82,7 @@ namespace CustomComponents } // Получаем атрибут, отвечающий за необходимость создания новой ветки var atr = prop.GetCustomAttributes()?.SingleOrDefault(atr => atr is AlwaysCreateAttribute); - bool isAlwaysCreate = false; - if (atr != null) - { - isAlwaysCreate = (atr as AlwaysCreateAttribute)!.IsAlwaysCreate; - } - dict[elem] = (prop.GetValue(obj)!, isAlwaysCreate); + dict[elem] = (prop.GetValue(obj)!, atr == null ? false : true); if (elem == propertyName) { diff --git a/COP/WinFormsTestApp/Form1.Designer.cs b/COP/WinFormsTestApp/Form1.Designer.cs index 7be8d93..4db773f 100644 --- a/COP/WinFormsTestApp/Form1.Designer.cs +++ b/COP/WinFormsTestApp/Form1.Designer.cs @@ -31,11 +31,17 @@ customCheckedListBox = new CustomComponents.CustomCheckedListBox(); customNumericUpDown = new CustomComponents.CustomNumericUpDown(); customTreeView = new CustomComponents.CustomTreeView(); + labelNumeric = new Label(); + labelTree = new Label(); + labelList = new Label(); + labelEvent = new Label(); + labelEventText = new Label(); + buttonClear = new Button(); SuspendLayout(); // // customCheckedListBox // - customCheckedListBox.Location = new Point(574, 34); + customCheckedListBox.Location = new Point(545, 118); customCheckedListBox.Name = "customCheckedListBox"; customCheckedListBox.SelectedValue = ""; customCheckedListBox.Size = new Size(188, 150); @@ -43,7 +49,7 @@ // // customNumericUpDown // - customNumericUpDown.Location = new Point(12, 34); + customNumericUpDown.Location = new Point(32, 147); customNumericUpDown.Max = new decimal(new int[] { 123, 0, 0, 0 }); customNumericUpDown.Min = new decimal(new int[] { 24, 0, 0, int.MinValue }); customNumericUpDown.Name = "customNumericUpDown"; @@ -54,22 +60,83 @@ // customTreeView // customTreeView.Hierarchy = null; - customTreeView.Location = new Point(280, 34); + customTreeView.Location = new Point(285, 80); customTreeView.Name = "customTreeView"; customTreeView.Size = new Size(188, 188); customTreeView.TabIndex = 2; // + // labelNumeric + // + labelNumeric.AutoSize = true; + labelNumeric.Location = new Point(64, 42); + labelNumeric.Name = "labelNumeric"; + labelNumeric.Size = new Size(115, 20); + labelNumeric.TabIndex = 3; + labelNumeric.Text = "CustomNumeric"; + // + // labelTree + // + labelTree.AutoSize = true; + labelTree.Location = new Point(333, 42); + labelTree.Name = "labelTree"; + labelTree.Size = new Size(87, 20); + labelTree.TabIndex = 4; + labelTree.Text = "CustomTree"; + // + // labelList + // + labelList.AutoSize = true; + labelList.Location = new Point(571, 42); + labelList.Name = "labelList"; + labelList.Size = new Size(162, 20); + labelList.TabIndex = 5; + labelList.Text = "CustomCheckedListBox"; + // + // labelEvent + // + labelEvent.AutoSize = true; + labelEvent.Location = new Point(64, 330); + labelEvent.Name = "labelEvent"; + labelEvent.Size = new Size(88, 20); + labelEvent.TabIndex = 6; + labelEvent.Text = "Event Label:"; + // + // labelEventText + // + labelEventText.AutoSize = true; + labelEventText.Location = new Point(170, 330); + labelEventText.Name = "labelEventText"; + labelEventText.Size = new Size(0, 20); + labelEventText.TabIndex = 7; + // + // buttonClear + // + buttonClear.Location = new Point(591, 274); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(94, 29); + buttonClear.TabIndex = 8; + buttonClear.Text = "Clear"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClear_Click; + // // Form1 // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(buttonClear); + Controls.Add(labelEventText); + Controls.Add(labelEvent); + Controls.Add(labelList); + Controls.Add(labelTree); + Controls.Add(labelNumeric); Controls.Add(customTreeView); Controls.Add(customNumericUpDown); Controls.Add(customCheckedListBox); Name = "Form1"; Text = "Form1"; ResumeLayout(false); + PerformLayout(); } #endregion @@ -77,5 +144,11 @@ private CustomComponents.CustomCheckedListBox customCheckedListBox; private CustomComponents.CustomNumericUpDown customNumericUpDown; private CustomComponents.CustomTreeView customTreeView; + private Label labelNumeric; + private Label labelTree; + private Label labelList; + private Label labelEvent; + private Label labelEventText; + private Button buttonClear; } } diff --git a/COP/WinFormsTestApp/Form1.cs b/COP/WinFormsTestApp/Form1.cs index 67390f9..327cb68 100644 --- a/COP/WinFormsTestApp/Form1.cs +++ b/COP/WinFormsTestApp/Form1.cs @@ -15,16 +15,23 @@ namespace WinFormsTestApp Someone teach2 = new Someone(" .", " ", ""); Someone teach3 = new Someone(" .", "", ""); Someone teach4 = new Someone(" .", "", ""); + Someone teach5 = new Someone(" .", "", ""); teachers.Add(teach1); teachers.Add(teach2); teachers.Add(teach3); teachers.Add(teach4); + teachers.Add(teach5); InitializeComponent(); - foreach(string st in list) + customNumericUpDown.ValueChanged += onNumericChange!; + customCheckedListBox.SelectChanged += onSelectedChange!; + + foreach (string st in list) { customCheckedListBox.DataList.Add(st); } + customCheckedListBox.SelectedValue = ""; loadTree(); + customTreeView.SelectedTreeNodeID = 2; } public void loadTree() @@ -35,5 +42,18 @@ namespace WinFormsTestApp customTreeView.AddNode(teach, "FIO"); } } + public void onNumericChange(object sender, EventArgs e) + { + labelEventText.Text = "Numeric changed value"; + } + public void onSelectedChange(object sender, EventArgs e) + { + labelEventText.Text = "Checked List changed selected"; + } + + private void buttonClear_Click(object sender, EventArgs e) + { + customCheckedListBox.ClearList(); + } } } diff --git a/COP/WinFormsTestApp/TestClasses/Someone.cs b/COP/WinFormsTestApp/TestClasses/Someone.cs index f1e0ea7..ef8799c 100644 --- a/COP/WinFormsTestApp/TestClasses/Someone.cs +++ b/COP/WinFormsTestApp/TestClasses/Someone.cs @@ -17,5 +17,6 @@ namespace WinFormsTestApp.TestClasses Position = pos; Facility = fac; } + public Someone() { } } }