After completion of today's lab, you should be able to
Microsoft's .NET provides two toolkits for user interface design: one for Web applications and the other for Windows applications.
Recently. Microsoft is promoting a new technology for developing user interfaces
Window Form applications rely on the power of the workstation (or local) computer for processing and high-performance content display.
Visual Studio.NET can be used to quickly create Visual C# Window applications.
Typically, inheritance is used to define a class that inherits from System.Windows.Forms.Form to create a window or dialog box visible on the GUI.
When using Visual Studio.NET's template for creating a Windows Form, a bunch of code is automatically written for you and placed behind the scene in a partial class ClassName.Designer.cs
namespace WindowsUI
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "Form1";
}
#endregion
}
}
Create a New Project called WindowsUI in Solution Lab2
WindowsUI as the project name, U:\Labs\ as the Location, and Lab2 as the solution name.MainForm.cs
Visual Studio.NET's Designer uses the Properties Window to facilitate the initialization of properties associated with forms and controls.
Set the initial properties of MainForm
MainForm in design view and select PropertiesChatter BoxU:\Labs\Lab2\WindowsUI\ foldertalker.ico image fileThe System.Windows.Forms namespace contains hundreds of built-in classes used to implement controls and components placed on forms.
Many of these controls are available through the Designer's Toolbox
Add a Multiline TextBox, a ComboBox, and a Button controls to your form
TextBox near the top of the form
ComboBox beneath the TextBox
Button beneath the ComboBox
Anchoring allows you to attach a control onto one of the form's corners. Anchored controls always stay a fixed distance from the point they are bound to.
Docking allows a control to bind itself to an edge in a form. When you resize the form, the control resizes itself to fit the entire edge.
Anchor and Dock your controls
Button and ComboBox to the bottom of your form.TextBox to the top of your formTextBox so that it fills the form when the form is resized Visual Studio automates the registering of the event handler with the control's event. It also prepares the method handling signature, all you need to do is write the C# code to handle the event (harder sometimes than it sounds).
Activity: Handle the Button Click Event
Visual Studio 2008 includes container controls that you can use to layout your controls on the form and that resize content as the screen size or user preferences change.
Activity: Experiment with the Layout controls
SplitContainer control to your form to show two text boxes, one for the initial text and the other for the translated text.TabControl to your form with three tabs: English, Spanish, and FrenchTableLayoutPanel to your form to experiment with using grid layout on a windows application
URL: http://www/cwu.edu /~gellenbe/446/labs/lab2.php
Author: Ed Gellenbeck, Department of Computer Science, Central Washington University, gellenbe@cwu.edu
Copyright 2006 Ed Gellenbeck, Central Washington University
Last modified: March 31, 2008