WISE OWL EXERCISES
VISUAL C# EXERCISES
- Creating forms (4)
- Coding form events (1)
- Laying out your code (2)
- C# variables (4)
- Enumerations and constants (2)
- Conditions (2)
- Modular code (3)
- Arrays (2)
- Looping (2)
- Files and folders (3)
- Properties in C# (3)
- Using lists (3)
- Validating forms (6)
- Toolbars, menus and status bars (1)
- FileDialogs and StreamReaders (1)
- Debugging and trapping errors (1)
- Introduction to DataGridViews (1)
- DataGridView events (3)
- Complex DataGridViews (2)
- Creating classes (2)
- The form as a class (1)
- Data structures (4)
- Inheritance (4)
- Interfaces (2)
- Delegates and events (2)
- Writing LINQ (1)
- Advanced LINQ (3)
- LINQ to SQL models (1)
- Writing LINQ to SQL (2)
- Grouping using LINQ (2)
Visual C# | Inheritance exercise | Create a form template by inheriting from Form class
This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.
The answer to the exercise will be included and explained if you attend the course listed below!
You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.
Suppose that whenever you create a form, you always set values for certain properties as follows:
|Text||You set the caption of the form when you first create it.|
|Height||120, 300 or 500, depending on whether the form is tidgy, mediumish or huge.|
|Width||200, 400 or 700, depending on whether the form is tidgy, mediumish or huge.|
What you'd like to be able to do is to write code like the following:
// create a new template form, setting its caption
FormTemplate ft = new FormTemplate("Wise Owl");
ft.size = FormTemplate.FormSize.Tidgy;
When you attach this code to a form button and run it, you'd like it to create and show a form on screen:
Clicking on a button in a test form should run this code to display a new form, with the caption, properties and size requested.
To get started, create a new class called FormTemplate, which should include an enumeration to determine the form size:
public enum FormSize
Your class will need to use the System.Windows.Forms namespace, and should inherit the Form class (so that it will behave like a form, with knobs on).
Add a constructor to your form which takes the form caption as an argument, and within this constructor set the start position, border style and caption.
Add a write-only property called Size which sets the dimensions of the form according to the value of the FormSize enumeration set.
Create the code shown at the start of this exercise to test out your class; running it should bring a form up on screen of the required size and with the required behaviour!