C# Graphical Interface

(last update: Tue Nov 10 12:27:56 CET 2015)

This course

Day 1: Introduction and First Steps

Sections V1 to V14

Day 2: Menus, Dialogs, more Controls

Buttons and text:

Menus:

General dialogs:

Exercises (from Cs-Exos-Partie2.pdf):

Day 3: Components, Containers, Drawing, Others

Components (no graphical representation):

Containers:

Tool Strips (toolbox strips)

Pictures, images, drawing:

Miscellaneous:

Exercises

Ex. 1: The Ecologist Programmer's Pet

Write an application that displays a main (modal) form. The form will contain:

When the user clicks on the button, your application will display a second (modal) form showing:

  • One GroupBox (labelled "Pet") containing three RadioButton, labelled "Cat", "Dog", "Platypus".
  • One CheckBox labelled "Are you an ecologist?".
  • One ComboBox (labelled "Choose favorite language") displaying a (non-editable) list of programming languages: "C", "C#", "Java", "Python".
  • Two Button, "Accept", and "Cancel".

If the user clicks on "Cancel":

  • the second form will close and one of the four Label in the first form will show "User cancelled".

If the user clicks on "Accept":

  • one of the labels will show "Accepted", and the remaining three will show the pet, the choice, and the programming language selected by the user.

Ex. 2: A Timer

We will write an application making use of the Timer component. Our application will have one single main window, with two buttons, labelled "Start" and "Stop". It will also have one Label that will display a number.

When the user clicks on "Start", the application will start a timer that tick 4 times per second. Every time the Tick event arrives, the application will increment the number displayed by the label. When the user clicks on "Stop", the number on screen stop incrementing.

Ex. 3: Background Worker + Progress Bar

Write an application which displays one single form with two buttons, one progress bar and one label. The buttons will start and stop a background worker (BackgroundWorker) which will execute the following code:

for i from 1 to 1000
  sleep 500 milliseconds
  report progress

Buttons:

  • "Start": it will start the background worker
  • "Stop": it will stop the background worker

Progress bar:

  • Whenever the worker reports progress, advance the progress bar

Label :

  • It will display the value of variale i in the loop

Extra: fix the window size to 500 pixels (horizontally) and 200 pixels (vertically), and prevent the user from resizing the window

Ex. 4: Picture Display with Zoom

We will write a program that can display images in BMP format. It will have a menu bar with the following entries:

  • "File", with submenus "Open ..." and "Quit"
  • "Help", with submenus "Help" and "About"
File > Open will display an OpenFileDialog and load the picture.
File > Quite will terminate the application
Help > Help will show an information message (MessageBox) saying that there is no help to show
Help > About will show your name

The window will have a status bar (StatusStrip) showing the coordinates of the mouse as you move it over the picture.

A mouse click with the left button will zoom in, a right click will zoom out.