diff --git a/COP/VisualComponentsLib/UserControl1.Designer.cs b/COP/VisualComponentsLib/MyDropDownList.Designer.cs similarity index 55% rename from COP/VisualComponentsLib/UserControl1.Designer.cs rename to COP/VisualComponentsLib/MyDropDownList.Designer.cs index ae6c37c..464b396 100644 --- a/COP/VisualComponentsLib/UserControl1.Designer.cs +++ b/COP/VisualComponentsLib/MyDropDownList.Designer.cs @@ -1,6 +1,6 @@ namespace VisualComponentsLib { - partial class UserControl1 + partial class MyDropDownList { /// /// Обязательная переменная конструктора. @@ -28,11 +28,32 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - } + this.comboBox = new System.Windows.Forms.ComboBox(); + this.SuspendLayout(); + // + // comboBox + // + 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); + // + // MyDropDownList + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.comboBox); + this.Name = "MyDropDownList"; + this.Size = new System.Drawing.Size(800, 450); + this.ResumeLayout(false); + this.PerformLayout(); + } - #endregion - } + #endregion + + private System.Windows.Forms.ComboBox comboBox; + } } diff --git a/COP/VisualComponentsLib/MyDropDownList.cs b/COP/VisualComponentsLib/MyDropDownList.cs new file mode 100644 index 0000000..ce17ddf --- /dev/null +++ b/COP/VisualComponentsLib/MyDropDownList.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace VisualComponentsLib +{ + public partial class MyDropDownList: UserControl + { + public MyDropDownList() + { + InitializeComponent(); + } + + public void LoadValues(List Values) + { + if (Values.Count == 0) + { + return; + } + comboBox.Items.AddRange(Values.ToArray()); + } + //Отдельный публичный метод отчистки списка. + public void Clear() + { + comboBox.Items.Clear(); + } + + //публичное свойство(set, get) для установки и получения выбранного значения (возвращает пустую строку, если нет выбранного значения) + public string SelectedValue + { + get + { + if (comboBox.Items.Count == 0) + { + return ""; + } + if (comboBox.SelectedItem == null) + { + return ""; + } + return comboBox.SelectedItem.ToString(); + } + set + { + if (comboBox.Items.Contains(value)) + { + comboBox.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); + } + } +} diff --git a/COP/VisualComponentsLib/MyDropDownList.resx b/COP/VisualComponentsLib/MyDropDownList.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/COP/VisualComponentsLib/MyDropDownList.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/COP/VisualComponentsLib/UserControl1.cs b/COP/VisualComponentsLib/UserControl1.cs deleted file mode 100644 index 831c08f..0000000 --- a/COP/VisualComponentsLib/UserControl1.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Data; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace VisualComponentsLib -{ - public partial class UserControl1: UserControl - { - public UserControl1() - { - InitializeComponent(); - } - } -} diff --git a/COP/VisualComponentsLib/VisualComponentsLib.csproj b/COP/VisualComponentsLib/VisualComponentsLib.csproj index d62b8d7..9c00681 100644 --- a/COP/VisualComponentsLib/VisualComponentsLib.csproj +++ b/COP/VisualComponentsLib/VisualComponentsLib.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - dc3c02aa-d21d-445e-a942-ee82e7f10228 + {DC3C02AA-D21D-445E-A942-EE82E7F10228} Library VisualComponentsLib VisualComponentsLib @@ -30,33 +30,31 @@ 4 - - - - - - - - - - - - - - - - + + + + + + + + + + - + UserControl - - UserControl1.cs + + MyDropDownList.cs - + + + MyDropDownList.cs + + - + \ No newline at end of file