OPI_RGZ_2011
.pdf121
public class NumberBox:System.Windows.Forms.TextBox
{
protected override void OnKeyPress (KeyPressEventArgs e)
{
if (char.IsNumber (e.KeyChar) = false) e.Handled = true;
}
}
A:+ B& *=&/ <:-.&C.D:E: - E5/+, &0.,12 3 45464. &- 47,- -*../
„ d , KK , –
d . ” 9
K , OnPaint, -
d . 5, o 9
, Region
OnPaint. J Region, 9 GraphicsPath, n 9 -
, K GraphicsPath. 6, (
GraphicsPath, o n d -
, 9'n Region
. v K n
:
public class WowButton: System.Windows.Forms.Button
{
protected override void OnPaintfPaintEventArgs pe)
{
System. Drawing. Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath ():
//QI78KL;I H6:I;CI @78I;6@?<r @?I78M@678D FontFamily 8I FontStyle
//R?9:9;8K H95K@I;;F 8IH, j6J 6J'rH8 GraphicsPath L59C78I@?F@
//Y6;8K5 5FCHI 7M:@6?D@ 56B:D56: 72 LK;H8M.
//[5ISKO89: K E# ;96JSDC;6
//t@;6 L9598@65M8M B;Ic9;;F Font.Style @ bD?9 cM7?6, myPath.AddString("Wow! ", Font.FontFamily, (int) Font.Style, 72, new PointF(0, 0), StringFormat.GenericDefault):
//E8@65M8M ;I 67;6@D GraphicsPath ;6@MO 6J'rH8 Region.
Region myRegion = new Region (myPath);
// 46:D78M8M ;6@MO 6J'rH8 Region @ 6C;6O:9;;9 @?I78M@D78T
// R?9:9;8K H95K@I;;F. this.Region = myRegion;
}
}
(, WowButton —
, o 9 ( n , n 9, o
«Wow!». ” 9 , 9
9, 9 ( 9. ' 9 KK
122
, o 9 -
. '. '-
, , TextBox, n
, K, d n. 6 n Paint, o -
n K o 9 9 n , -
9.
8 :
–K
;
–9 (
, o n .
( -:74../ 0 5*+:- 3 45464. &- 47,-*../
J, 9 , 9'n- K ( K -
Windows Forms, K d K
. J n
9 , 9'n
. A UserControl
, (
.
7 9 ( 9 9 , - K . ', o -
9 , - n . ' 9-
n
9 ( . ' 9 n -
, d .nKeyPress -
:
//W?F L6CDG KeyPress 9?9:9;8I H95K@I;;F TextBox2
//4685DJ;6 78@65M8M I;I?6UDc;MO 6J56J;MH.
protected override void OnKeyPress (object sender, KeyPressEventArgs e)
{
// 4959@D5M8M, cM r ;I8M7;K8I H?I@DeI bM•56@6<. if (char.IsNumber (e.KeyChar) == false) e.Handled = true;
Label1.Text = (int.Parse (TextBox1.Text) + int.Parse (TextBox2.Text)). ToString ();
}
123
: ( K-
. 6 ( 9, 9 K d
, ( -
, , . ” 9
d 9 K -
, 9 9'n
. 7 -
K K (Button1). ” 9
BackColor 9'n Button1, , ,
— 9 9'n , (:
public color ButtonColor
{
get
{
return Buttonl. BackColor:
}
set
{
Buttonl. BackColor = value;
}
}
” 9 ,
Modifiers. v ( Properties
9, n. :-
Modifiers n 9- , -
n . u :
–, UserControl;
–UserControl K
Windows Forms,
;
–9 9
;
–(, 9
.
( -:74../ B:76:-*. 3 45464. &- 47,-*../
2 K (
d K K nK K, - 9 n 9 d . . 9 Control n
o 9 , 9
124
, o n 9 -
. u o , n
9 .
' n 9
n . .d -
, n Paint, -
K 9 9 Paint. Control 9 9
Paint n OnPaint.
OnPaint n n —
PaintEventArgs, o K n 9
. : — Graphics
ClipRectangle.
Graphics — 9'n Graphics, o n n
9 . ' 9 -
9 ( . ClipRectangle — -
, n 9 . ' d
9 ( ClipRectangle 9 ( n
9. u o n d ,
( 9 K . '
ClipRectangle n
9, 9 . 8 -
n 9'n ClipRectangle n Size.
K
, d n -
(0,0), 9 KK . 5 -
n OnPaint, o n
:
// w9O L5MH?IC L5MLK7HIr ;IF@;D78T 6L95I865I Imports System.Drawing protected override void OnPaint (PaintEventArgs e)
{
Brush aBrush = new SolidBrush (Color.Red);
Rectangle clientRectangle = new Rectangle (new Point (0,0), this.Size);
e.Graphics.FillEllipse (aBrush, clientRectangle);
}
' Kn
ClipRectangle,
9 (. ” 9 -
( K , -
125
Control.SetStyle ResizeRedraw true,
:
SetStyle (ControlStyles.ResizeRedraw, true);
s6J K JKCT-FHMO cI7 L959:I?<@I8M 9?9:9;8 H95K@I;;F @5Kc;K, C678I8;T6 @MH?MHI8M :986C Refresh:
Refresh();
tH 78@65M8M •65:6@I;MO 9?9:9;8 H95K@I;;F: 6U6?67D8T H?I7, L6SDC;MO @DC H?I7K Control;
C6CIO89 @ :986C OnPaint H6C, j6 @DBKI?DBKr 9?9:9;8 H95K@I;;F.
7 (, 9 d -
.
4.2.2.3!') ) , !, ( &, !') , F 8 '/'-' %! ' ! )
' 9 9- K
, d, d d. 5 -
d , ( K 9
.
( ! ) '/'-' %! ' ! ) '/b Toolbox
, ( K. ” 9
9 9 9-
9 , Toolbox,
9- ( .
v n d Customize Toolbox, -
K Toolbox. J K -
K Toolbox 9- Customize Toolbox, o 9 -
Customize Toolbox. 9 - ( , 9
Toolbox.
A
Toolbox:
–K K d Toolbox 9 -
Customize Toolbox — n ;
–.NET Framework Components
Browse, o 9 File;
–DLL 9 s‡s- ,
9 . : 9
Open;
126
– ', o 9
Customize Toolbox .J —
' Toolbox.
N , &' ) & '/'-' ' ! )
Visual Studio .NET n 9 ( -
, Toolbox, ( -
n 9 (. A -
, 9. 9 ( Toolbox
K K ToolboxBitmapAttribute — -
9, o n . : - n 9 (
16x16 9 Type (type). : -
Kn ,
9'n .
0 9 ToolbaxBitmapAttribute d
. Visual C# 9 K
( ( K d -
, d. u -
, d 9 (: ( - 9 ( K 9 ToolboxBitmapAttribute:
[ToolboxBitmap (@ "C:\Pasta.bmp")] public class PastaMaker : Control
{
// A9I?DBIbDF 6LKj9;I.
}
u :
d 9
ToolboxBitmapAttribute -:
[ToolboxBitmap(typeof (Button))] public class myButton: Button
{
/ / A9I?DBIbDF 6LKj9;I.
}
/ # (.' ) '/'-' %! ' ! )
9 9- n
(, . .
n , ( 9 -
127
Windows Forms. ' -
9 K.
' , d
, ( d (,
.
u o d n K
, Windows Forms, -
, o -
9 9 9 ,
d .
5 ( Windows Forms:
–d, 9 d K Build -
Build Solution;
–9 9 -
K ;
–-
9 . d K
Toolbox, o 9 9 d K
9;
–, d F5, — ( -
( : -, d ( 9, o K ;
–d , K , o 9 . A 9 - K Build Rebuild Solution. 5 (
9 9 9 :
–d, 9 d K Build -
Build Solution;
–K File 9 Add Project \ New Project, o 9
d , — n
Add New Project;
–Add New Project 9 Windows Application, ' .J;
–Solution Explorer K K d
References 9 K
Add Reference — n Add Reference;
128
–Projects. u o , o -
, ,
(¢, Browse
DLL- , ( n -
. : .J.
–-
9 . d
Toolbox, 9
9;
–, d F5 — ( -
( : -, d ( 9, o
K .
' ! ) /%c' ! )- '/'-' %! ' ! )
: .NET Framework n 9 -
. y -
n K :
9-
. , , n, o 9
9 9 License Provider Attribute, o n 9'n License.
Provider — 9 -
. License Provider — 9 , o n -
.
LicenseManager. Validate, o 9 -
K. u o -, ( K. License Manager. Validate n GetLicense 9'n License Provider, n K n K
IsKeyValid 9'n LicenseProvider. u o IsKeyValid n true,
( n K, -
( n.
(
LicenseProvider. .NET — LicenseProvider n
LieFileLicenseProvider. u o LicenseProvider,
n . GetLicense
d n DLL-
129
' FullName.LIC, FullName — ' -. ' IsKeyValid n d
«my ClassName is a licensed component», myClassName — ' . 7 9
, d . ( 9
Dispose, , ' -
K .
. n Widget, o -
n K LieFileLicenseProvider.
//w9O L5MH?IC L5MLK7HIr ;IF@;D78T 6L95I865I Imports System.ComponentModel
//w9 I85MJK8 LicenseProvider, FHMO @HIBKr 8ML @_M@I;6U6
//LicenseProvider.
[LicenseProvider (typeof (LieFileLicenseProvider))] public class Widget: System.Windows.Forms.Control
{
private License myLicense; public Widget ()
{
//4959@D5M8M ?Db9;BD< 8I 685M:I8M L67M?I;;F ;I ;9G. myLicense = LicenseManager.Validate (typeof (Widget), this);
//y;eMO H6C H6;785KH865I 6LKj9;MO.
}
//w9 :986C Dispose, j6 B@D?T;Fr 597K57M,
//46@'FBI;D B L959@D5H6< ?Db9;BDG.
protected override void Dispose (bool Disposing)
{
if (myLicense != null)
{
myLicense.Dispose (); myLicense = null;
}
}
}
7 :
–( LicenseProvider, d d
9 LicenseProviderAttribute;
–License, 9 9
LicenseProvider;
LicenseManager. Validate ;
–, K , d
Dispose .
130
! .' ) '/'-' ' ! ) ! Internet Explorer
€ - Windows Forms ( (-
Internet Explorer. v n 9 HTML- d-
( .
n, .
” 9 ( Internet Explorer, -
n ( d 9 9 (Global Assembly Cache, GAC) 9 HTML-
K, d. A d -
Windows Forms HTML- ( <OBJECT>,
n 9'n. 6 <OBJECT> n ( 9'n
classid, ( ( Windows Forms K .
: classid Windows Forms - n : d -
, «#».
5 ( <OBJECT>, d n
' ControlLibrary1.myControl,
ControlLibrary1.dll, d -
HTML-K:
<OBJECT id = "myControl"
classid = "http:ControlLibrary1.dll#ControlLibrary1.myControl" VIEWASTEXT>
</ OBJECT>
( Internet Explorer:
–d DLL-
HTML- , d, 9 GAC;
–HTML- <OBJECT> -
classid. : classid K n d
DLL- ' , «#».
4.3 !( ) ( F ,
4.3.1.
K 9, K , ( -
.
4.3.28 , - 9 (, .