Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
551 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
Software ==> | Visual C# (55 exercises) |
Topic ==> | Inheritance (5 exercises) |
Level ==> | Harder than average |
Subject ==> | C# training |
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.
Create a form with a button in (the answer form is imaginatively called Form3, but you can probably improve on this name):
The idea is that you can click on the button to create "labels" and text boxes. The labels will actually be textboxes with background colour, border style and enabled properties reset.
When you click on the form, we'll arrange it so that you can draw editable and non-editable textboxes on the form:
An example of what clicking on the form might show.
Here is some example code to attach to the button, which should (when you've created the requisite classes) draw the editable and non-editable textboxes as shown in the previous diagram:
// first name label
DisplayTextBox lblFirstName = new DisplayTextBox(
this, 30, 30, 180, 50);
lblFirstName.Text = "Enter first name:";
lblFirstName.Add();
// last name label
DisplayTextBox lblLastName = new DisplayTextBox(
this, 30, 80, 180, 50);
lblLastName.Text = "Enter last name:";
lblLastName.Add();
// first name text box
EditableTextBox txtFirstName = new EditableTextBox(
this, 240, 30, 100, 50);
txtFirstName.Add();
// last name text box
EditableTextBox txtLastName = new EditableTextBox(
this, 240, 80, 100, 50);
txtLastName.Add();
To get this to work, you will create DisplayTextBox and EditableTextBox classes which both inherit from an abstract BaseTextBox class (which in turn should inherit from System.Windows.Forms.Textbox).
If you get this all working, try creating a second button which adds the "label" and textbox in one go:
This button should do exactly the same thing, using the different code below.
Here's an example of what the code attached to this second button could look like:
// create the two "label"/textbox combinations - the answer uses
// a structure for the TextAndLabel type.
TextAndLabel tl = new TextAndLabel(this,30,30,"Enter first name");
tl.Create();
TextAndLabel t2 = new TextAndLabel(this, 30, 80, "Enter last name");
t2.Create();
You now understand inheritance!
You can find other training resources for the subject of this exercise here:
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.