Showing posts with label Winform Code. Show all posts
Showing posts with label Winform Code. Show all posts

Friday, August 9, 2024

Winform -Data Binding to a List

Create a form that displays a list of names in a `ListBox`. Populate the `ListBox` with some sample data when the form loads.


1. Add a `ListBox` to the form.
2. In the form’s `Load` event, populate the `ListBox` with data.

```csharp
private void Form1_Load(object sender, EventArgs e)
{
    List<string> names = new List<string> { "Alice", "Bob", "Charlie" };
    listBox1.DataSource = names;
}

Create a simple WinForms application



Create a simple WinForms application with a form that has a `TextBox`, a `Button`, and a `Label`. When the button is clicked, the text entered in the `TextBox` should be displayed in the `Label`.

1. Create a new WinForms project.
2. Add a `TextBox`, a `Button`, and a `Label` to the form.
3. Double-click the button to generate a click event handler.
4. In the event handler, set the `Label`'s text to the `TextBox`'s text.

```csharp
private void button1_Click(object sender, EventArgs e)
{
    label1.Text = textBox1.Text;
}

Your Title