This commit is contained in:
ElEgEv 2023-09-13 10:30:37 +04:00
parent bb487bf6e1
commit 1605f4c548
3 changed files with 54 additions and 1 deletions

View File

@ -29,6 +29,9 @@
private void InitializeComponent() private void InitializeComponent()
{ {
listBox = new ListBox(); listBox = new ListBox();
buttonAdd = new Button();
textBox = new TextBox();
buttonRemove = new Button();
SuspendLayout(); SuspendLayout();
// //
// listBox // listBox
@ -41,20 +44,54 @@
listBox.Size = new Size(234, 229); listBox.Size = new Size(234, 229);
listBox.TabIndex = 0; listBox.TabIndex = 0;
// //
// buttonAdd
//
buttonAdd.Location = new Point(261, 52);
buttonAdd.Name = "buttonAdd";
buttonAdd.Size = new Size(114, 23);
buttonAdd.TabIndex = 1;
buttonAdd.Text = "Добавить";
buttonAdd.UseVisualStyleBackColor = true;
buttonAdd.Click += ButtonAdd_Click;
//
// textBox
//
textBox.Location = new Point(252, 12);
textBox.Name = "textBox";
textBox.Size = new Size(133, 23);
textBox.TabIndex = 2;
//
// buttonRemove
//
buttonRemove.Location = new Point(261, 96);
buttonRemove.Name = "buttonRemove";
buttonRemove.Size = new Size(114, 23);
buttonRemove.TabIndex = 3;
buttonRemove.Text = "Очистить список";
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += ButtonRemove_Click;
//
// UserListBox // UserListBox
// //
AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
Controls.Add(buttonRemove);
Controls.Add(textBox);
Controls.Add(buttonAdd);
Controls.Add(listBox); Controls.Add(listBox);
Location = new Point(3, 5); Location = new Point(3, 5);
MinimumSize = new Size(84, 53); MinimumSize = new Size(84, 53);
Name = "UserListBox"; Name = "UserListBox";
Size = new Size(240, 240); Size = new Size(398, 240);
ResumeLayout(false); ResumeLayout(false);
PerformLayout();
} }
#endregion #endregion
private ListBox listBox; private ListBox listBox;
private Button buttonAdd;
private TextBox textBox;
private Button buttonRemove;
} }
} }

View File

@ -32,5 +32,20 @@ namespace VisualComponentsLib.CustomListBox
add => listBox.Items.Add(value); add => listBox.Items.Add(value);
remove => listBox.Items.Clear(); remove => listBox.Items.Clear();
} }
private void ButtonAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(textBox.Text))
{
listBox.Items.Add(textBox.Text);
textBox.Text = string.Empty;
}
}
private void ButtonRemove_Click(object sender, EventArgs e)
{
listBox.Items.Clear();
}
} }
} }

View File

@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<Folder Include="CustomTextBox\" /> <Folder Include="CustomTextBox\" />
<Folder Include="CustomListBox\" />
<Folder Include="CustomDataGridView\" /> <Folder Include="CustomDataGridView\" />
</ItemGroup> </ItemGroup>