of 38
8/16/2019 Visual Inheritance and user Defined Controls
1/38
Programming III
Visual Inheritance
and User-Defined
Controls
8/16/2019 Visual Inheritance and user Defined Controls
2/38
Visual Inheritance and UserControls
Upon completion of this work, the learner shall as a
means of designing and building a user-defined
control The student shall be capable of creating .NET
components with Visual Studio .NET using a Class
ibrar! pro"ect, and using the # files in C$
applications
2
8/16/2019 Visual Inheritance and user Defined Controls
3/38
Visual Inheritance(1/12)
Visual inheritance enables !ou to achie%e
%isual consistenc!.
&or e'ample, !ou could define a base Form that contains a product(s logo and a specific
background color.
)ou then could use the baseForm
throughoutan app for uniformit! and branding.
3
8/16/2019 Visual Inheritance and user Defined Controls
4/38
Visual Inheritance(2/12)
Class VisualInheritanceBaseForm *&ig. +.
deri%es from &orm.
/e use the public classVisualInheritanceBaseForm
. Use the namespace declaration that was created for us b!
the 0#E.
1ight click the pro"ect name in the Solution !"lorer and
select Pro"erties, then choose the #""lication tab.
0n the $ut"ut t!pe drop-down list, change %indo&s
#""lication to Class 'irar.
2uilding the pro"ect produces the *dll.
+
8/16/2019 Visual Inheritance and user Defined Controls
5/38
Visual Inheritance(3/12)
,
8/16/2019 Visual Inheritance and user Defined Controls
6/38
Visual Inheritance(+/12)
8/16/2019 Visual Inheritance and user Defined Controls
7/38
Visual Inheritance(,/12)
To %isuall! inherit from
VisualInheritanceBaseForm, create a new
/indows Forms app. 0n this app, add a reference to the .dll !ou
"ust created.
3odif! the line that defines the class4public partial class VisualInheritanceTestForm :
VisualInheritanceBase.VisualInheritanceBaseForm
.
8/16/2019 Visual Inheritance and user Defined Controls
8/38
8/16/2019 Visual Inheritance and user Defined Controls
9/38
Visual Inheritance(./12)
0
8/16/2019 Visual Inheritance and user Defined Controls
10/38
Visual Inheritance(/12)
1
8/16/2019 Visual Inheritance and user Defined Controls
11/38
Visual Inheritance(0/12)
11
8/16/2019 Visual Inheritance and user Defined Controls
12/38
8/16/2019 Visual Inheritance and user Defined Controls
13/38
Visual Inheritance(11/12)
13
8/16/2019 Visual Inheritance and user Defined Controls
14/38
Visual Inheritance(12/12)
1+
8/16/2019 Visual Inheritance and user Defined Controls
15/38
User-Defined Controls
The .NET &ramework allows !ou to create
custom controls.
Custom controls appear in the user(sToolbox.
There are multiple wa!s to create a custom
control, depending on the le%el ofcustomi7ation that !ou want *&ig. +.8.
1,
8/16/2019 Visual Inheritance and user Defined Controls
16/38
User-Defined Controls
1
8/16/2019 Visual Inheritance and user Defined Controls
17/38
User-Defined Controls
1.
8/16/2019 Visual Inheritance and user Defined Controls
18/38
8/16/2019 Visual Inheritance and user Defined Controls
19/38
Im"lement a User-Defined Control
10
8/16/2019 Visual Inheritance and user Defined Controls
20/38
imer Control
2
8/16/2019 Visual Inheritance and user Defined Controls
21/38
User-Defined Controls
Timers are non-%isual components that generate Tick e%ents ata set inter%al.
The Timer(s Interal propert! defines the number of
milliseconds between e%ents. Create a UserControl class for the pro"ect b! selecting Pro4ect
5 #dd User Control 6.
/e name the file *and the class ClockUserControl.
9dd a Label and a Timer to the UserControl.
Set the Timer inter%al to 1000 milliseconds.
clockTimer must be enabled b! setting Enabled to true
21
8/16/2019 Visual Inheritance and user Defined Controls
22/38
User-Defined Controls
&igure +.: shows the output of Clock,
which contains our ClockUserControl.
22
8/16/2019 Visual Inheritance and user Defined Controls
23/38
User-Defined Controls
23
8/16/2019 Visual Inheritance and user Defined Controls
24/38
Consume the User Defined Control(1/.)
2+
8/16/2019 Visual Inheritance and user Defined Controls
25/38
Consume the User Defined Control(2/.)
2,
7ight clic8
$n 9eneral
8/16/2019 Visual Inheritance and user Defined Controls
26/38
Consume the User Defined Control(3/.)
2
8/16/2019 Visual Inheritance and user Defined Controls
27/38
Consume the User Defined Control(+/.)
2.
8/16/2019 Visual Inheritance and user Defined Controls
28/38
Consume the User Defined Control(,/.)
2
8/16/2019 Visual Inheritance and user Defined Controls
29/38
Consume the User Defined Control(/.)
20
8/16/2019 Visual Inheritance and user Defined Controls
30/38
Consume the User Defined Control(./.)
3
8/16/2019 Visual Inheritance and user Defined Controls
31/38
Create a %indo&s :orm oolo! Control(1/.)
The /indows &orms Toolbo' Control template
creates a user defined control and pro%ides all
of the functionalit! that is re;uired to add thecontrol to the oolo!.
31
8/16/2019 Visual Inheritance and user Defined Controls
32/38
Create a %indo&s :orm oolo! Control(2/.)
32
8/16/2019 Visual Inheritance and user Defined Controls
33/38
Create a %indo&s :orm oolo! Control(3/.)
33
8/16/2019 Visual Inheritance and user Defined Controls
34/38
Create a %indo&s :orm oolo! Control(+/.)
3+
8/16/2019 Visual Inheritance and user Defined Controls
35/38
8/16/2019 Visual Inheritance and user Defined Controls
36/38
Create a %indo&s :orm oolo! Control(/.)
8/16/2019 Visual Inheritance and user Defined Controls
37/38
Create a %indo&s :orm oolo! Control(./.)
3.
8/16/2019 Visual Inheritance and user Defined Controls
38/38
7eferences
.NET #ocumentation
Te'tbook, Chap +
https4==msdn.microsoft.com=en-us=librar!=mt5>?6>5.asp
' https4==
msdn.microsoft.com=en-us=librar!=ms@??>+?.asp
' https4==msdn.microsoft.com=en-
=lib = 6+@6@3
https://msdn.microsoft.com/en-us/library/mt683786.aspxhttps://msdn.microsoft.com/en-us/library/mt683786.aspxhttps://msdn.microsoft.com/en-us/library/mt683786.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/ms233813.aspxhttps://msdn.microsoft.com/en-us/library/mt683786.aspxhttps://msdn.microsoft.com/en-us/library/mt683786.aspxhttps://msdn.microsoft.com/en-us/library/mt683786.aspxhttps://msdn.microsoft.com/en-us/library/mt683786.aspx