Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
A WFA with a single form, with the following elements:
- A listBox
- Two buttons that say "Add" and "Delete"
- A button that says "Exit"
- A TextBox
If there is content in the TextBox, it will be copied to ListBox when the "Add" button is clicked.
Also, the content in the TextBox will be automatically deleted when it is added to the listBox.
The "Delete" button will delete the selected line from the listBox, and the "Exit" button will close the application.

What I have tried:

i've searched for a solution but i didn't find it
Posted
Updated 25-May-20 1:46am

Create a solution, with a WinForms project.
Drop the five controls only to the form and set their Name properties appropriately.
Set the buttons Text properties to the labels you have been given.
And handlers to the button Click events.

Fill in the code for the handlers.

You aren't going to find the exact code you need for this anywhere: it's your teachers invention, so you are going to have to write your own code in order to submit your homework. This is normal, and expected: the idea of "development" is as the word suggests: "The systematic use of scientific and technical knowledge to meet specific objectives or requirements." BusinessDictionary.com[^]
That's not the same thing as "have a quick google and give up if I can't find exactly the right code".
 
Share this answer
 
As Griff said, you won't find the exact code for your problem but here's a basic tutorial:
C# Windows Forms Application Tutorial with Example[^]
 
Share this answer
 
If there is content in the TextBox, it will be copied to ListBox when the "Add" button is clicked.
Also, the content in the TextBox will be automatically deleted when it is added to the listBox.
This is done in the event handler for the Click event of the Add button:
C#
private void buttonAdd_Click(object sender, EventArgs e)
{
   theList.Items.Add(theTextBox.Text);
   theTextBox.Text = string.Empty;
}

The "Delete" button will delete the selected line from the listBox, and the "Exit" button will close the application.
This is done by implementing corresponding event handlers as well:
C#
private void buttonDelete_Click(object sender, EventArgs e)
{
   theList.Items.RemoveAt(theList.SelectedIndex);
}

private void buttonExit_Click(object sender, EventArgs e)
{
   Application.Exit();
}

I would also add some event handlers to enable or disable buttons based on the content of the textbox and the selected item in the list:
C#
private void theTextBox_Validated(object sender, EventArgs e)
{
   buttonAdd.Enabled = !string.IsNullOrEmpty(theTextBox.Text);
}

private void theList_SelectedIndexChanged(object sender, EventArgs e)
{
   buttonDelete.Enabled = theList.SelectedIndex != -1;
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900