Where is the form in Visual Studio?

Delegates will learn to develop web applications using C# 4.0. After completing this course, delegates will be able to:

  • Use Visual Studio 2010 effectively
  • Windows Forms with C# using Visual Studio 2010

Audience

This course has been designed primarily for programmers new to the .Net development platform. Delegates experience solely in Windows application development or earlier versions of ASP.Net will also find the content beneficial.

Prerequisites

Before attending this workshop, students must:

  • Be able to manage a solution environment using the Visual Studio 2010 IDE and tools
  • Be able to program an application using a .NET Framework 4.0 compliant language

Contents

Copyright 20/12/12 – David Ringsell

Download Solutions

Where is the form in Visual Studio?

Quick Access

List of Contents
Exercise 1 – Creating the Customer Form
Exercise 2 – Enhancing the Customer Form
Exercise 3 – Explore further Windows Forms features

Exercise 1 – Creating a Custom Text Box
Exercise 2 – Testing the Custom Text Box on a Form
Exercise 3 – Creating a User Control
Exercise 4 – Testing the User Control on a Form
Exercise 5 – Creating a Custom About Box Form

Lab 1. Building Applications with Windows Forms
Exercise 1
Creating the Customer Form
In this exercise, you will create a form that to show customer information. You will later add a MenuStrip, ToolStrip and other controls to this form.

Where is the form in Visual Studio?

  1. Create the Windows Application project:
    • Start Visual Studio 2010.
    • Select the File menu, then New, then Project.
    • Make sure (if you are using the Professional Version) that Visual C# and
      then Windows is selected at the left of the screen under Installed Templates.
    • Name the project and the solution: Customers.
    • Browse to the place on your computer where you wish Visual Studio
      to create the directory for your solution (keeping the tick box selected).
    • Select Windows Forms Application.
  2. Add a Windows Form to the project called frmCustomers:
    • Right-click on the project name: Customers.
    • Select Add.
    • Select New Item.
    • Select Windows form.
  3. Add the list box and text boxes to the form as shown above.
  4. Set the Anchor properties of the text box controls.
  5. Test the project confirm that all controls are anchored correctly.
  6. Using the Toolbox, add a MenuStrip control.
  7. Add a File and a Help menu to the MenuStrip control.
  8. Add the following sub-menus:
    • File: Load Customers, Exit.
    • Help: About.

Exercise 2
Enhancing the Customer Form
In this exercise, you will enhance the customer form by adding a ToolStrip and a ToolTip control. You will also add functionality to the MenuStrip and ToolStrip.

  1. Using the Toolbox, add a ToolStrip control.
  2. Add 3 buttons to the ToolStrip.
  3. Set the Text and the ToolTipText properties for the buttons to:
    • Load Customers
    • Exit
    • Help
  4. Add an About box to the project by right clicking the project name in Solution Explorer.
  5. Add event handlers for the menu items. For example:
    private void loadCustomersToolStripMenuItem_Click(object sender, EventArgs e)
    {
       this.Close();
    }
  6. Add event handlers for the tool strip button. For example:
    private void ToolStripButton2_Click(object sender, EventArgs e)
    {
       //The Exit toolstrip button calls the Exit menu event handler
       loadCustomersToolStripMenuItem_Click(sender, e);
    }
  7. Add ToolTip user assistance by dragging a ToolTip control on to the form designer, then setting the list box’s ToolTip property.

Exercise 3
Explore further Windows Forms features
In this exercise, you will enhance the customers form to open a second form. You will add container controls & provider controls to this second form.

Where is the form in Visual Studio?

  1. Add another form to the project called frmCustomerDetails and open this form from the customers form:
    • using the ShowDialog method (modal).
    • as an owned form (non-modal).
  2. You can do this by double-clicking the button and adding this code to the event handler:

    //Show a second form
    frmCustomerDetails f = new frmCustomerDetails();
    //Show as a dialog box (modal)
    f.ShowDialog();
    //Show as a owned form (non-modal)
    //this.AddOwnedForm(f);
    //f.Show();

    By adding the forward-slash to the beginning of the sentence, the following text in the sentence is not treated as code by the compiler; it is commented out. For it to compile and execute as code, just remove the forward slash characters from the sentence. By commented out code you can choose which code you want to have activated in your program.

    What is form in Visual Studio?

    Visual Basic Form is the container for all the controls that make up the user interface. Every window you see in a running visual basic application is a form, thus the terms form and window describe the same entity. Visual Studio creates a default form for you when you create a Windows Forms Application.

    How can I get Windows form application in Visual Studio 2022?

    Create a Windows Forms app.
    Open Visual Studio..
    Select Create a new project..
    In the Search for templates box, type winforms, and then press Enter ..
    In the code language dropdown, choose C# or Visual Basic..
    In the templates list, select Windows Forms App (..