From ecfe9ba9cea8e1d05f65c584600538d522dcd505 Mon Sep 17 00:00:00 2001 From: bekodeg Date: Tue, 10 Sep 2024 10:37:02 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=82=D0=B0=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Components/CustomListBox.Designer.cs | 57 +++++++++ .../Components/CustomListBox.cs | 69 ++++++++++ .../Components/CustomListBox.resx | 120 ++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.Designer.cs create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.cs create mode 100644 Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.resx diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.Designer.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.Designer.cs new file mode 100644 index 0000000..9eb12b7 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.Designer.cs @@ -0,0 +1,57 @@ +namespace Cop.Borovkov.Var3.Components +{ + partial class CustomListBox + { + /// + /// Обязательная переменная конструктора. + /// + 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() + { + InerlistBox = new ListBox(); + SuspendLayout(); + // + // inerlistBox + // + InerlistBox.Dock = DockStyle.Fill; + InerlistBox.FormattingEnabled = true; + InerlistBox.Location = new Point(0, 0); + InerlistBox.Name = "inerlistBox"; + InerlistBox.Size = new Size(150, 150); + InerlistBox.TabIndex = 0; + InerlistBox.ValueMemberChanged += InerlistBox_ValueMemberChanged; + // + // CustomListBox + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(InerlistBox); + Name = "CustomListBox"; + ResumeLayout(false); + } + + #endregion + + private ListBox InerlistBox; + } +} diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.cs b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.cs new file mode 100644 index 0000000..ba73c93 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.cs @@ -0,0 +1,69 @@ +namespace Cop.Borovkov.Var3.Components +{ + public partial class CustomListBox : UserControl + { + private event EventHandler? _valueChanged; + private event Action? _errorOccured; + + /// + /// + public CustomListBox() + { + InitializeComponent(); + } + + /// + /// Событие возникающие при изменении списка + /// + public event EventHandler ValueChanged + { + add => _valueChanged += value; + remove => _valueChanged -= value; + } + + /// + /// Обработка ошибок + /// + public event Action AnErrorOccurred + { + add => _errorOccured += value; + remove => _errorOccured -= value; + } + + /// + /// Заполнить список значениями + /// + /// Список значений + public void FillValues(IEnumerable strings) + { + InerlistBox.Items.Clear(); + InerlistBox.Items.AddRange(strings.ToArray()); + } + + /// + /// Очистить список + /// + public void Clear() => InerlistBox.Items.Clear(); + + private void InerlistBox_ValueMemberChanged(object sender, EventArgs e) + { + try + { + _valueChanged?.Invoke(sender, e); + } + catch (Exception ex) + { + _errorOccured?.Invoke(ex); + } + } + + /// + /// Выбранное значение + /// + public string Selected + { + get => (string?)InerlistBox.SelectedItem ?? string.Empty; + set => InerlistBox.SelectedItem = value; + } + } +} diff --git a/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.resx b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Cop.Borovkov.Var3/Cop.Borovkov.Var3/Components/CustomListBox.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