diff --git a/VisualComponentsForm/VisualComponentsForm.sln b/VisualComponentsForm/VisualComponentsForm.sln index fbe2fe0..2ac4581 100644 --- a/VisualComponentsForm/VisualComponentsForm.sln +++ b/VisualComponentsForm/VisualComponentsForm.sln @@ -4,14 +4,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 17.6.33815.320 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponentsForm", "VisualComponentsForm\VisualComponentsForm.csproj", "{29E20B1C-11E3-4B0D-A614-097ACBB21263}" - ProjectSection(ProjectDependencies) = postProject - {317EA9D6-B5A5-44FE-B524-D646B518CB3E} = {317EA9D6-B5A5-44FE-B524-D646B518CB3E} - EndProjectSection EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "VisualComponentsLib", "..\VisualComponentsLib\VisualComponentsLib.csproj", "{F5B8AE30-4836-44F8-AC47-75D2B05D73EF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WinFormsMyComponents", "..\WinFormsMyComponents\WinFormsMyComponents.csproj", "{317EA9D6-B5A5-44FE-B524-D646B518CB3E}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -26,10 +21,6 @@ Global {F5B8AE30-4836-44F8-AC47-75D2B05D73EF}.Debug|Any CPU.Build.0 = Debug|Any CPU {F5B8AE30-4836-44F8-AC47-75D2B05D73EF}.Release|Any CPU.ActiveCfg = Release|Any CPU {F5B8AE30-4836-44F8-AC47-75D2B05D73EF}.Release|Any CPU.Build.0 = Release|Any CPU - {317EA9D6-B5A5-44FE-B524-D646B518CB3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {317EA9D6-B5A5-44FE-B524-D646B518CB3E}.Debug|Any CPU.Build.0 = Debug|Any CPU - {317EA9D6-B5A5-44FE-B524-D646B518CB3E}.Release|Any CPU.ActiveCfg = Release|Any CPU - {317EA9D6-B5A5-44FE-B524-D646B518CB3E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs b/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs index dbd1c5a..6fa9db0 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.Designer.cs @@ -28,90 +28,107 @@ /// private void InitializeComponent() { - this.labelCheck = new System.Windows.Forms.Label(); - this.buttonCheck = new System.Windows.Forms.Button(); - this.myListBox1 = new VisualComponentsLib.CustomListBox.MyListBox(); - this.textBox1 = new System.Windows.Forms.TextBox(); - this.button1 = new System.Windows.Forms.Button(); - this.button2 = new System.Windows.Forms.Button(); - this.SuspendLayout(); + labelCheck = new Label(); + buttonCheck = new Button(); + myListBox = new VisualComponentsLib.CustomListBox.MyListBox(); + textBoxInput = new TextBox(); + buttonAddList = new Button(); + buttonClear = new Button(); + groupBox = new GroupBox(); + groupBox.SuspendLayout(); + SuspendLayout(); // // labelCheck // - this.labelCheck.AutoSize = true; - this.labelCheck.Location = new System.Drawing.Point(522, 23); - this.labelCheck.Name = "labelCheck"; - this.labelCheck.Size = new System.Drawing.Size(38, 15); - this.labelCheck.TabIndex = 1; - this.labelCheck.Text = "label1"; + labelCheck.AutoSize = true; + labelCheck.BorderStyle = BorderStyle.FixedSingle; + labelCheck.Location = new Point(296, 139); + labelCheck.Name = "labelCheck"; + labelCheck.Size = new Size(40, 17); + labelCheck.TabIndex = 1; + labelCheck.Text = "label1"; // // buttonCheck // - this.buttonCheck.Location = new System.Drawing.Point(532, 71); - this.buttonCheck.Name = "buttonCheck"; - this.buttonCheck.Size = new System.Drawing.Size(75, 23); - this.buttonCheck.TabIndex = 2; - this.buttonCheck.Text = "Проверка"; - this.buttonCheck.UseVisualStyleBackColor = true; - this.buttonCheck.Click += new System.EventHandler(this.ButtonCheck_Click); + buttonCheck.Location = new Point(279, 166); + buttonCheck.Name = "buttonCheck"; + buttonCheck.Size = new Size(75, 23); + buttonCheck.TabIndex = 2; + buttonCheck.Text = "Проверка"; + buttonCheck.UseVisualStyleBackColor = true; + buttonCheck.Click += ButtonCheck_Click; // - // myListBox1 + // myListBox // - this.myListBox1.Location = new System.Drawing.Point(12, 12); - this.myListBox1.MinimumSize = new System.Drawing.Size(84, 53); - this.myListBox1.Name = "myListBox1"; - this.myListBox1.Size = new System.Drawing.Size(242, 240); - this.myListBox1.TabIndex = 3; + myListBox.Location = new Point(6, 22); + myListBox.MinimumSize = new Size(84, 53); + myListBox.Name = "myListBox"; + myListBox.SelectedString = null; + myListBox.Size = new Size(242, 240); + myListBox.TabIndex = 3; // - // textBox1 + // textBoxInput // - this.textBox1.Location = new System.Drawing.Point(323, 26); - this.textBox1.Name = "textBox1"; - this.textBox1.Size = new System.Drawing.Size(100, 23); - this.textBox1.TabIndex = 4; + textBoxInput.Location = new Point(254, 25); + textBoxInput.Name = "textBoxInput"; + textBoxInput.Size = new Size(100, 23); + textBoxInput.TabIndex = 4; // - // button1 + // buttonAddList // - this.button1.Location = new System.Drawing.Point(341, 69); - this.button1.Name = "button1"; - this.button1.Size = new System.Drawing.Size(75, 23); - this.button1.TabIndex = 5; - this.button1.Text = "button1"; - this.button1.UseVisualStyleBackColor = true; + buttonAddList.Location = new Point(279, 54); + buttonAddList.Name = "buttonAddList"; + buttonAddList.Size = new Size(75, 23); + buttonAddList.TabIndex = 5; + buttonAddList.Text = "Добавить"; + buttonAddList.UseVisualStyleBackColor = true; + buttonAddList.Click += ButtonAddList_Click; // - // button2 + // buttonClear // - this.button2.Location = new System.Drawing.Point(299, 114); - this.button2.Name = "button2"; - this.button2.Size = new System.Drawing.Size(75, 23); - this.button2.TabIndex = 6; - this.button2.Text = "button2"; - this.button2.UseVisualStyleBackColor = true; + buttonClear.Location = new Point(279, 83); + buttonClear.Name = "buttonClear"; + buttonClear.Size = new Size(75, 23); + buttonClear.TabIndex = 6; + buttonClear.Text = "Очистить"; + buttonClear.UseVisualStyleBackColor = true; + buttonClear.Click += ButtonClear_Click; + // + // groupBox + // + groupBox.Controls.Add(myListBox); + groupBox.Controls.Add(buttonClear); + groupBox.Controls.Add(labelCheck); + groupBox.Controls.Add(buttonAddList); + groupBox.Controls.Add(buttonCheck); + groupBox.Controls.Add(textBoxInput); + groupBox.Location = new Point(12, 12); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(368, 271); + groupBox.TabIndex = 7; + groupBox.TabStop = false; + groupBox.Text = "Первый компонент"; // // FormMain // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Controls.Add(this.button2); - this.Controls.Add(this.button1); - this.Controls.Add(this.textBox1); - this.Controls.Add(this.myListBox1); - this.Controls.Add(this.buttonCheck); - this.Controls.Add(this.labelCheck); - this.Name = "FormMain"; - this.Text = "Form1"; - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(400, 297); + Controls.Add(groupBox); + Name = "FormMain"; + Text = "Form1"; + groupBox.ResumeLayout(false); + groupBox.PerformLayout(); + ResumeLayout(false); } #endregion private Label labelCheck; private Button buttonCheck; - private VisualComponentsLib.CustomListBox.MyListBox myListBox1; - private TextBox textBox1; - private Button button1; - private Button button2; + private VisualComponentsLib.CustomListBox.MyListBox myListBox; + private TextBox textBoxInput; + private Button buttonAddList; + private Button buttonClear; + private GroupBox groupBox; } } \ No newline at end of file diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.cs b/VisualComponentsForm/VisualComponentsForm/FormMain.cs index ae0c68d..438771a 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.cs +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.cs @@ -9,7 +9,19 @@ namespace VisualComponentsForm private void ButtonCheck_Click(object sender, EventArgs e) { - + labelCheck.Text = myListBox.SelectedString; + } + + private void ButtonAddList_Click(object sender, EventArgs e) + { + myListBox.AddItem(textBoxInput.Text); + + textBoxInput.Text = string.Empty; + } + + private void ButtonClear_Click(object sender, EventArgs e) + { + myListBox.ClearAll(); } } } \ No newline at end of file diff --git a/VisualComponentsForm/VisualComponentsForm/FormMain.resx b/VisualComponentsForm/VisualComponentsForm/FormMain.resx index f298a7b..af32865 100644 --- a/VisualComponentsForm/VisualComponentsForm/FormMain.resx +++ b/VisualComponentsForm/VisualComponentsForm/FormMain.resx @@ -1,4 +1,64 @@ - + + + diff --git a/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj b/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj index eb55cd9..08a2169 100644 --- a/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj +++ b/VisualComponentsForm/VisualComponentsForm/VisualComponentsForm.csproj @@ -10,7 +10,6 @@ - \ No newline at end of file diff --git a/VisualComponentsLib/MyListBox.Designer.cs b/VisualComponentsLib/MyListBox.Designer.cs index fec6703..e3833fb 100644 --- a/VisualComponentsLib/MyListBox.Designer.cs +++ b/VisualComponentsLib/MyListBox.Designer.cs @@ -28,31 +28,30 @@ /// private void InitializeComponent() { - this.listBox = new System.Windows.Forms.ListBox(); - this.SuspendLayout(); + listBox = new ListBox(); + SuspendLayout(); // // listBox // - this.listBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left))); - this.listBox.FormattingEnabled = true; - this.listBox.ItemHeight = 15; - this.listBox.Location = new System.Drawing.Point(3, 3); - this.listBox.Name = "listBox"; - this.listBox.Size = new System.Drawing.Size(234, 229); - this.listBox.TabIndex = 0; + listBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left; + listBox.FormattingEnabled = true; + listBox.ItemHeight = 15; + listBox.Location = new Point(3, 3); + listBox.Name = "listBox"; + listBox.Size = new Size(234, 229); + listBox.TabIndex = 0; + listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged; // // MyListBox // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.listBox); - this.Location = new System.Drawing.Point(3, 5); - this.MinimumSize = new System.Drawing.Size(84, 53); - this.Name = "MyListBox"; - this.Size = new System.Drawing.Size(242, 240); - this.ResumeLayout(false); - + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + Controls.Add(listBox); + Location = new Point(3, 5); + MinimumSize = new Size(84, 53); + Name = "MyListBox"; + Size = new Size(242, 240); + ResumeLayout(false); } #endregion diff --git a/VisualComponentsLib/MyListBox.cs b/VisualComponentsLib/MyListBox.cs index 7dd1894..72819da 100644 --- a/VisualComponentsLib/MyListBox.cs +++ b/VisualComponentsLib/MyListBox.cs @@ -14,17 +14,27 @@ namespace VisualComponentsLib.CustomListBox public partial class MyListBox : UserControl { [Browsable(true)] - public string selectedString + public string SelectedString { - get => listBox.SelectedItem.ToString(); + get + { + if (listBox.SelectedItems.Count == 0) + { + return null; + } + else + { + return listBox.SelectedItem.ToString(); + } + } - set + set { if (!string.IsNullOrEmpty(value) && listBox.Items.IndexOf(value) != -1) { listBox.SelectedItem = value; } - } + } } public MyListBox() @@ -32,13 +42,7 @@ namespace VisualComponentsLib.CustomListBox InitializeComponent(); } - public event EventHandler? TextChanged - { - add => listBox.TextChanged += value; - remove => listBox.TextChanged -= value; - } - - public void addItem(string item) + public void AddItem(string item) { if (!string.IsNullOrEmpty(item)) { @@ -46,9 +50,22 @@ namespace VisualComponentsLib.CustomListBox } } - public void clearAll() + public void ClearAll() { listBox.Items.Clear(); } + + private EventHandler _textChanged; + + public event EventHandler? TextChanged + { + add => _textChanged += value; + remove => _textChanged -= value; + } + + private void ListBox_SelectedIndexChanged(object sender, EventArgs e) + { + _textChanged?.Invoke(sender, e); + } } } diff --git a/VisualComponentsLib/MyListBox.resx b/VisualComponentsLib/MyListBox.resx index f298a7b..af32865 100644 --- a/VisualComponentsLib/MyListBox.resx +++ b/VisualComponentsLib/MyListBox.resx @@ -1,4 +1,64 @@ - + + +