Form+Modification

=Forms= Forms are known as Graphical User Interfaces or GUI, pronounced gooey. Up until this point we have been using an interface that only allows for text to be entered or displayed. Forms allow for graphics and text to be arranged in an easy to use interface that we have all grown to love.

To start the creation of a new form project click on New project.

Then the project window will open and look like below. Double click the windows forms application. Be sure to name your project at this point to make things easier for you in the future.



The window
Below is a sample window for us to discuss. On the far bottom right there is a window called properties here you can set the properties of anything you click on. There are many many properties to explore. A few worth mentioning are name, and text. The name field allows you to name the object you have clicked on so that you can use it later in the code. For example, the "+" button is named btn_add. The "btn" means that it is a button and is named in that manner so that you can easily refer to it in the code. The text box is named txt_number1 and "txt" reminds you that you are referring to a text box. The text property is what will be displayed on the form. For the btn_add the text is "+"

So you might be asking "Well, how do I create the darn things you are talking about?" Well do you see the Toolbox icon in the upper left corner of the screen. Move your mouse over that and a window should grow out of the left side and look like below.



We will mainly use the text box and buttons in what we will do but you should recognize many of the icons from your everyday windows interactions.

Take a few minutes to make the form below. It uses text boxes and buttons. The grayed out box that says "results" is a special type of text box. Create a regular text box and find the property that says "ReadOnly" Change this property from false to true to create that object.

Whoa! I said create that object up there! That's right you created an object graphically. You could also set that property in your code. It would look like this: code txt_result.ReadOnly = True; code This is extremely handy.

You can create the title by using a label and changing the text.

Go ahead and make this form now:



Looks great right?

Now we need to get to the code portion of the form. To get there right click on the form and click view code. Now we can really do some damage!

Lets start to make those buttons do something. To get started double click on the button you want to add functionality to. Good, now the code window should be up and look like below.



we can now add code under the btn_add_click function.

I would write something like this:

code double number_1; double number_2; double result;

number_1 = txt_number1.text; number_2 = txt_number2.text;

result = add(number_1,number_2);

code

This will call a add function that needs to be created yet. But this is how this would begin to look.