diff --git a/COP/VisualComponentsLib/MyDropDownList.Designer.cs b/COP/VisualComponentsLib/MyDropDownList.Designer.cs index 464b396..c797b53 100644 --- a/COP/VisualComponentsLib/MyDropDownList.Designer.cs +++ b/COP/VisualComponentsLib/MyDropDownList.Designer.cs @@ -28,32 +28,32 @@ /// private void InitializeComponent() { - this.comboBox = new System.Windows.Forms.ComboBox(); + this.dropDownList = new System.Windows.Forms.ComboBox(); this.SuspendLayout(); // - // comboBox + // dropDownList // - this.comboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBox.FormattingEnabled = true; - this.comboBox.Location = new System.Drawing.Point(3, 3); - this.comboBox.Name = "comboBox"; - this.comboBox.Size = new System.Drawing.Size(187, 24); - this.comboBox.TabIndex = 0; - this.comboBox.SelectedValueChanged += new System.EventHandler(this.comboBox_SelectedValueChanged); + this.dropDownList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.dropDownList.FormattingEnabled = true; + this.dropDownList.Location = new System.Drawing.Point(3, 3); + this.dropDownList.Name = "dropDownList"; + this.dropDownList.Size = new System.Drawing.Size(187, 24); + this.dropDownList.TabIndex = 0; + this.dropDownList.SelectedValueChanged += new System.EventHandler(this.comboBox_SelectedValueChanged); // // MyDropDownList // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.comboBox); + this.Controls.Add(this.dropDownList); this.Name = "MyDropDownList"; - this.Size = new System.Drawing.Size(800, 450); + this.Size = new System.Drawing.Size(193, 30); this.ResumeLayout(false); - this.PerformLayout(); + } #endregion - private System.Windows.Forms.ComboBox comboBox; + private System.Windows.Forms.ComboBox dropDownList; } } diff --git a/COP/VisualComponentsLib/MyDropDownList.cs b/COP/VisualComponentsLib/MyDropDownList.cs index ce17ddf..89ac7da 100644 --- a/COP/VisualComponentsLib/MyDropDownList.cs +++ b/COP/VisualComponentsLib/MyDropDownList.cs @@ -23,54 +23,39 @@ namespace VisualComponentsLib { return; } - comboBox.Items.AddRange(Values.ToArray()); + dropDownList.Items.AddRange(Values.ToArray()); } - //Отдельный публичный метод отчистки списка. public void Clear() { - comboBox.Items.Clear(); + dropDownList.Items.Clear(); } - //публичное свойство(set, get) для установки и получения выбранного значения (возвращает пустую строку, если нет выбранного значения) public string SelectedValue { get { - if (comboBox.Items.Count == 0) + if (dropDownList.Items.Count == 0) { return ""; } - if (comboBox.SelectedItem == null) + if (dropDownList.SelectedItem == null) { return ""; } - return comboBox.SelectedItem.ToString(); + return dropDownList.SelectedItem.ToString(); } set { - if (comboBox.Items.Contains(value)) + if (dropDownList.Items.Contains(value)) { - comboBox.SelectedItem = value; + dropDownList.SelectedItem = value; } - } } - private EventHandler _event; - public event EventHandler Event - { - add - { - _event += value; - } - remove - { - _event -= value; - } - } - //событие, вызываемое при смене значения в ComboBox. private void comboBox_SelectedValueChanged(object sender, EventArgs e) { - _event?.Invoke(sender, e); + if (dropDownList.BackColor == Color.LightGreen) dropDownList.BackColor = Color.Tomato; + else dropDownList.BackColor = Color.LightGreen; } } } diff --git a/COP/WinForms/Form1.Designer.cs b/COP/WinForms/Form1.Designer.cs index db172ba..2e29a58 100644 --- a/COP/WinForms/Form1.Designer.cs +++ b/COP/WinForms/Form1.Designer.cs @@ -28,12 +28,82 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; + dropDownList = new VisualComponentsLib.MyDropDownList(); + buttonAdd = new Button(); + buttonInfo = new Button(); + labelInfo = new Label(); + buttonClear = new Button(); + SuspendLayout(); + // + // dropDownList + // + dropDownList.Location = new Point(3, 3); + dropDownList.Margin = new Padding(3, 4, 3, 4); + dropDownList.Name = "dropDownList"; + dropDownList.SelectedValue = ""; + dropDownList.Size = new Size(196, 36); + dropDownList.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(3, 46); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(92, 29); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonInfo + // + buttonInfo.Location = new Point(211, 46); + buttonInfo.Name = "buttonInfo"; + buttonInfo.Size = new Size(94, 29); + buttonInfo.TabIndex = 2; + buttonInfo.Text = "показать"; + buttonInfo.UseVisualStyleBackColor = true; + buttonInfo.Click += buttonInfo_Click; + // + // labelInfo + // + labelInfo.AutoSize = true; + labelInfo.Location = new Point(205, 9); + labelInfo.Name = "labelInfo"; + labelInfo.Size = new Size(154, 20); + labelInfo.TabIndex = 3; + labelInfo.Text = "Выбранный элемент"; + // + // buttonClear + // + buttonClear.Location = new Point(101, 46); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(94, 29); + buttonClear.TabIndex = 4; + buttonClear.Text = "очистить"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += buttonClear_Click; + // + // Form1 + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dropDownList); + Controls.Add(buttonAdd); + Controls.Add(buttonInfo); + Controls.Add(labelInfo); + Controls.Add(buttonClear); + Name = "Form1"; + Text = "Form1"; + ResumeLayout(false); + PerformLayout(); } #endregion + private VisualComponentsLib.MyDropDownList dropDownList; + private Button buttonAdd; + private Button buttonInfo; + private Label labelInfo; + private Button buttonClear; } } \ No newline at end of file diff --git a/COP/WinForms/Form1.cs b/COP/WinForms/Form1.cs index 780e67b..b4964f5 100644 --- a/COP/WinForms/Form1.cs +++ b/COP/WinForms/Form1.cs @@ -2,9 +2,27 @@ namespace WinForms { public partial class Form1 : Form { + List list = new List(); public Form1() { + list = new List(); + list.AddRange(new string[] { "", "", "" }); InitializeComponent(); + dropDownList.LoadValues(new List() { "", "", "" }); + } + private void buttonAdd_Click(object sender, EventArgs e) + { + dropDownList.LoadValues(list); + } + + private void buttonInfo_Click(object sender, EventArgs e) + { + labelInfo.Text = dropDownList.SelectedValue; + } + + private void buttonClear_Click(object sender, EventArgs e) + { + dropDownList.Clear(); } } } \ No newline at end of file diff --git a/COP/WinForms/Form1.resx b/COP/WinForms/Form1.resx index 1af7de1..af32865 100644 --- a/COP/WinForms/Form1.resx +++ b/COP/WinForms/Form1.resx @@ -1,17 +1,17 @@  - diff --git a/COP/WinForms/WinForms.csproj b/COP/WinForms/WinForms.csproj index b57c89e..6a94a95 100644 --- a/COP/WinForms/WinForms.csproj +++ b/COP/WinForms/WinForms.csproj @@ -8,4 +8,8 @@ enable + + + + \ No newline at end of file