Search This Blog

Wednesday, April 20, 2011

C# programming Basics part 3 - Adding Forms and the Visibility Property

Sometimes, one form is not sufficient to contain all the things you would like to happen in the program.In this case,you must add another form or forms to the project. To add a form, first right click on the name of the project in the properties window and select add then select new item from the list this displays. Select windows form, name the form, and add it to the project. Next you must allow the form to be displayed through a button press on the first form. Add a button to both forms. Name the button on the first form (I named it bttncontinue) and adjust its text property to something like CONTINUE. Name the button on the second form (I named it bttnclose) and adjust its text property to something like CLOSE or BACK TO MAIN. Now You are ready to program. First, right click on bttncontinue to bring up the code screen. Then, simply enter this code (I chose to name the first form mainform and the second form subform):

subform myNewForm = new subform();
myNewForm.ShowDialog();
That's all it takes to add a new form in C#.
One very useful tool in C# programming is the ability to make things appear and disappear at the will of the user. If you want something, like a button for example, to be invisible at the beginning of the program, simply go under the section of code "Initialize Component" (after its last closing Bracket but before the first "private void section")and enter this code (assuming the item is named invisibilitycloak:

invisibilitycloak.Visible = false;

To make it reappear at the press of a button, double click on the button and enter the following code (same name):

invisibilitycloak.Visible = true;

That's all I have on this subject.
See you next time on Hayden@Earth

No comments:

Post a Comment