Resources

Creating User Interfaces in C# using WinForms

Lesson 1

User Interface Design Principles

Forms, Controls, Menus

Composition

Lesson 2

Using Forms

Adding Forms to Project

// Assumes form called DialogForm 
// already designed by you

DialogForm myform

Myform = new dialogForm()

Visual Inheritance

or

  1. To inherit from form outside project click Browse and navigate to appropriate application. Click Open and choose desired Form.
// Derive from MainForm residing within project
public class myForm : MainForm
{

}

Set Startup Form

static void Main()
{

}

Form Start Location

Changing Appearance

// Change form colour within its implementation
this.BackColor = System.Drawing.Color.Red;

BackColor, ForeColor, Text Properties

Font, Cursor, BackGroundImage

Opacity

Form Methods

Form Events

Lesson 3

Using Controls and Components

Working with Controls and Components

Control Tab Order

Controls Can Contain Other Controls

Control aControl;

aControl = myForm.Controls[3];

myForm.RemoveAt(2);

Docking and Anchoring Controls

Extender Providers

// Retrieve ToolTip for button1
String myToolTip;

myToolTip = toolTip1.GetToolTip(button1);

// Set tooltip for button1
toolTip1.SetToolTip(button1, "Click this button for help");

Lesson 4

Using Menus

Creating Menus at Design Time

Access and Shortcut Keys

Menu Item Events

Context Menus

Enable / Disable Menu Commands

Check Marks On Menu

Radio Buttons On Menu

Menu Item Visibility

Cloning Menus

// Declare + instantiate context menu
ContextMenu myContextMenu = new ContextMenu();

// Clone fileMenuItem
myContextMenu.MenuItems.Add(fileMenuItem.CloneMenu());

//Attach context menu to myButton
myButton.ContextMenu = myContextMenu;

Merge Menus

mainMenu1.MergeMenu(contextMenu1);

Add Menu Items

// Define event handler
Public void ClickHandler (object sender, System.EventArgs e)
{

...

}

MenuItem myItem;

myItem = new MenuItem ("Item 1", new EventHandler(myClick));

MainMenu1.MenuItems.Add(myItem);

Lesson 5

Validating User Input

Field-level Validation

Form-level Validation

User Feedback

myErrorProvider.SetError( nameTextBox, "Name cannot be blank");

Downloads