[Solved] How to approach: Write a Windows application that accepts any number of positive values [closed]


Though I don’t understand the project in entirety. This should at least point you in a solid direction.

  1. Open Visual Studio
  2. Select C#
  3. Choose Windows Form Application

At this point your project will open with a canvas, in designer mode. To help describe what is happening click the Form once.

On the right-hand side of your Window you will see Solution Explorer and Properties.

Solution Explorer: This will show you the contents of your project. It contains the following:

  • Properties: Assembly, Resource, and Settings information.
  • References: This will contain all your project references, Assemblies that help expand your project or link to other applications you may be doing.

The next item, is going to be your Form. This is the most important part; because this will be where all your manipulation will be.

Now the second item I mentioned; Properties. Not the one in Solution Explorer but the tab that stands apart. Will show you all the modifications for that component. In this case, your Form.

On the left-hand side what you’ll do is actually go to Toolbox. These are all the components that Microsoft provides you right out of the gate. Simply drag the Textbox Component out of the Toolbox onto your Form (canvas).

You’ll notice the outline, with several transformation dots for you to manipulate location and dimensions.

Before we move further I’ll break it down what has happened. You’ve input a blank textbox onto your Form. By default it will be called TextBox1. It is good practice to identify the component with what it is then it’s desired function. If your looking for lets say a users first name, name it txtFirst. That way it is easier to understand what your manipulating.

Since my goal is to help point you in the right direction, follow these steps:

  1. Drag a Label– Name it lblInput (Change text to name of your choice).
  2. Drag out a Textbox– Name it txtInput.
  3. Drag out a Rich Textbox – Name it rtxtDisplay.

Now these three components will inherently be your User Interface. All of the interaction will occur here. But we are missing one Element to the interface. A button, this is important because it will create what is called an Event. These will essentially notify the interface of a change so it appears that it is doing something.

  • Drag a Button out of the Toolbox, name is btnAdd.

Now you have an entire interface; so now double click on the button. Your screen will now change; you’ll see all of this text.

The important part is where it navigated you to by selecting the button.

private void btnAdd_Click(object sender, EventArgs e)
{
     // Implementation Here.
}

So that will provide you the Event so you can perform your logic to create your application. Now, I’m not going to do your code for you. But I’ll do something close so you can adapt and learn.

private void btnAdd_Click(object sender, EventArgs e)
{
    // Method One: "Casting"
    // By default txtInput is a String, you require integers.  So you can add.
    /* So you would want to ensure proper Error Handling exists, otherwise when you cast you'll receive an invalid cast exception. */
    txtInput.Text = (int)data;
}

So as you can see the // and /* are different methods to comment to make your logic easy to understand. I’m using it to explain what is happening for you. The txtInput.Text takes whatever input string value and is now being casted to an integer.

private void btnAdd_Click(object sender, EventArgs e)
{
     // Method Two: "Array"
     int[] data;
}

Now, this will actually allocate a reference in your memory. Which will allow you to store multiple things into the Array. This method would work well if you pass all your textbox input into your Rich Textbox. Then a second button could fill the array to add each item.

In this example I will actually write an entire aspect but as I stated you’ll need to do certain things to make it meet your needs.

public partial class Form1 : Form
{
   // Create Storage
   List<string> store = new List<string>();

   private void button1_click(object sender, EventArgs e)
   {
       // Will add the input of the textbox to list each time button clicked.
       store.Add(textbox1.Text);
   }

   private void button2_click(object sender, EventArgs e)
   {
       // Logic to Add the items.
   }
}

There is half your battle right there. Things to help you truly understand this conceptually, will be these items to help you complete your project.

  • Casting
  • Arrays
  • Generics
  • Loops

Hopefully that helps you. Those are some basic lessons; I might suggest the entry level tutorial courses on MSDN.

solved How to approach: Write a Windows application that accepts any number of positive values [closed]