Сдано йо

This commit is contained in:
Marselchi 2024-09-06 10:48:03 +04:00
parent 0b6c2765ec
commit 7204b0c1c9
6 changed files with 104 additions and 15 deletions

View File

@ -8,9 +8,7 @@ namespace CustomComponents.Attributes
{
public class AlwaysCreateAttribute : Attribute
{
public bool IsAlwaysCreate { get; }
public AlwaysCreateAttribute()
{ IsAlwaysCreate = true; }
{ }
}
}

View File

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

View File

@ -68,7 +68,7 @@ namespace CustomComponents
private Dictionary<string, (object, bool)> _getValuesWithStructure<T>(T obj, string propertyName)
{
PropertyInfo[]? properties = obj!.GetType().GetProperties();
PropertyInfo[]? properties = obj?.GetType().GetProperties();
var dict = new Dictionary<string, (object, bool)>();
// Получаем все значения свойств в структурированном виде (относительно иерархии)
@ -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)
{

View File

@ -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;
}
}

View File

@ -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();
}
}
}

View File

@ -17,5 +17,6 @@ namespace WinFormsTestApp.TestClasses
Position = pos;
Facility = fac;
}
public Someone() { }
}
}