OPI_RGZ_2011
.pdf81
byte a = byte.Parse (Console.ReadLine ()); Console.WriteLine ("b =");
byte b = byte.Parse (Console.ReadLine ()); int f = 1;
try / / X6@;De;DO J?6H-try
{
for (byte i = a; i <= b; + + i)
{
try / / [;K85De;DO J?6H-try
{
f = checked ((int) (f * i));
Console.WriteLine ("y ({0}) = {1: f6}", i, 100 / (f - 1));
}
catch (DivideByZeroException)
{
Console.WriteLine ("y ({0}) = WD?9;;F ;I 0", i);
}
}
}
catch (ArithmeticException)
{
Console.WriteLine ("ERROR");
}
: try-9 9 9 ( 9- 9 9. .
K K. „ d — 9 d , (
. 6 d try-9 ( ,
K d try-9 9 9 d 9. ' 2. :, n catch-nK,
( , o 9 9 ( -
d (d) catch-nK. v n -
9 9 .
static void genException ()
{
Console.WriteLine ("a =");
double a = double.Parse (Console.ReadLine ()); Console.WriteLine ("b =");
double b = double.Parse (Console.ReadLine ()); int f = 1;
try / / X6@;De;DO J?6H-try
{
for (double i = a; i <= b; + + i)
{
try / / [;K85De;DO J?6H-try
{
f = checked ((int) (f * i));
82
Console.WriteLine ("y ({0}) = {1: f6}", i, 100 / (f - 1));
}
catch (DivideByZeroException)
{
Console.WriteLine ("y ({0}) = WD?9;;F ;I 0", i);
}
}
}
catch (ArithmeticException)
{
Console.WriteLine ("ERROR");
throw; / / L6@865;I U9;95IbDF @M;F8HK
}
}
static void Main ()
{
try
{
genException ();
}
catch
{
Console.WriteLine ("•I8I?T;I L6:M?HI !!!");
}
}
' 9 ' , o
9 K n ( catch-nK,
n (d) catch- .
' 3. u o, 9
, catch- . : d
9 . ( K , K-
catch-K 9 . J , try-9 (' , catch- . catch-
K . u o
( , o 9 , ( -
catch-K 9 .
(. „ n 9 9'
, o try/catch- 9. 5, n 9 n -
d , d- n . A 8 # n 9 finally, n 9 catch.
static void Main ()
{
for (int i = 0; i <5; i + +)
83
{
try
{
Console.WriteLine ("[@9CD8T C@I cM7?I"); int a = int.Parse (Console.ReadLine ()); int b = int.Parse (Console.ReadLine ()); Console.WriteLine (a +"/"+ b +"="+ a / b);
}
catch (FormatException)
{
Console.WriteLine ("4685DJ;6 @@978M cM7?6!");
}
catch (DivideByZeroException)
{
Console.WriteLine ("WD?M8M ;I ;K?T ;9 :6_;I!");
}
catch
{
Console.WriteLine ("tHI7T L6:M?HI");
}
finally
{
Console.WriteLine ("LD7?F try-J?6HK");
}
}
}
3.3 !( )
3.3.1.
K 9, K , ( -
.
3.3.28 ( ,
, K 9 9 .
3.3.3. .
3.3.4: .
3.4 -% !%
3.4.16 9.
3.4.29.
3.4.3J .
3.4.4J .
84
3.4.5 :, o (5 d. 9 ), ( 9 ( K -
9 .
3.5/b % , )
3.5.1” K ?
3.5.2u K?
3.5.3u K?
3.5.4” K?
3.5.5u K?
3.5.6u 9 K ?
3.5.7u K « » d?
3.5.8” 9 & K? u 9
K?
3.5.9u K?
3.5.10u K 9 (?
3.5.11u K K ?
3.5.12” ?
3.5.13u 9 9 ? '
( 9 ?
3.5.14u 9 9 ?
3.5.155 ’ 9 9 .
3.5.16J Exception. . ?
3.5.175 o 9 ?
3.5.18u 9 K ?
3.5.19u ?
3.5.205 o try-9?
85
4 OM-P Q R * 4 o M R L
M R M #
4.1 ' F ,
4.1.15
4.1.25 K .
4.2 ! % ' ' ,& % !%(-%
4.2.1
9- , ( ,
9 . A , .NET Framework
9 PrintDocument, o 9 n
n '
K .
€ , ( n nK ( d
. 5 ( K , o 9 d K 9- K , - 9 ( 9 K
. 6 9 9 K
. .NET Framework n ,
( d K n
nK.
4.2.1.1-' PrintDocument
.NET Framework -
PrintDocument.
‡ PrintDocument n , -
Windows Forms
Toolbox, ( ,
. .9'n PrintDocument Kn K K,
9 . n : PrinterSettings 9 n ( -
86
, Default PageSettings Kn -
, a PrintController Kn 9 9 .
v K n -
.
! ' ) F'x PrintDocument
.9'n PrintDocument ( 9, -
K , 9 ,
. d 9'n PrintDocument
Toolbox 9 ' -
9'n,
9 .
. Kn 9'n PrintDocument: PrintDocument myPrintDocument = new PrintDocument();
. 9'n PrintDocument -
n 9 -
.
N%( ,- (
, .NET Framework, o K
9, K . :
PrintDocument, Print Kn , K
PrintPage. u o n 9 9 n ,
n. ” 9 , 9
9 9 PrintPage.
u o n ,
PrintPage n ( , 9 9 n -
n 9. .9 9 K PrintPage Kn -
, 9 K 9-
; 9 9 d
d .
N (%) PrintPage
' PrintPage n K . ” 9 -
, 9 9 9
PrintPage , o n
. 9'n, 9 , K 9 9-
9'n PrintPageEventArgs, 9. 4.1.
87
6 9 4.1 – : 9'n PrintPageEventArgs
„' |
. |
Cancel |
: n, |
Graphics |
9'n Graphics, o n |
|
|
HasMorePages |
. n 9 Kn , n, |
|
|
MarginBounds |
. n 9'n Rectangle, o n 9- |
|
, 9 ( |
PageBounds |
. n 9'n Rectangle, o n - |
|
|
PageSettings |
. n 9 Kn 9'n PageSettings |
|
|
A -
n 9'n Graphics, PrintPageEventArgs.
n n ( , o n
9 , 9- d
K, 9'n Graphics. A -
K ( , o K
. . ( , - n , 9, 9 ( :
//s6J b9O :986C JK@ @MH?MHI;MO, @D; L6@M;9; 6J56J?F8M7F L6CDr<
//PrintPage.
public void PrintEllipse (object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawEllipse (Pens.Black, e.MarginBounds);
}
: MarginBounds PageBounds K 9 -
, . ( 9 9 -
, 9 d 9'n
MarginBounds. ' ( -
— , o 9 ( -
. A 9'n
PageBounds. u , -
, 9 KK .
88
: HasMorePages n , n -
9. K
false. u o ( 9 9 9 -
, true, d
— false.
'. .9 9 PrintPage ( - K , d
9 9. 8 (, o -
HasMorePages false,
9 PrintPage .
J , 9 ( ,
K . A
Cancel true.
” 9 9 9 PrintPage, -
PrintDocument ( Kn 9 9 -
) 9 9 9 .
4.2.1.2,!%( (
” 9 , Print Document, Print. n, ,
n , .
#$% ,
A d, ( K
. A 9 K 9'n Graphics,
9'n PrintPageEventArgs. A K , 9 d
, K 9'n GraphicsPath. . K 9'n-
Graphics Path:
/ / w9O :986C L6@M;;I 6J56J?F8M L6CDF PrintPage. public void PrintGraphics (object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath myPath = new System.Drawing.Drawing2D.GraphicsPath (); myPath.AddPolygon (new Point [] {new Point (1, 1), new
Point (12, 55), new Point (34, 8), new Point (52, 53),new Point (99, 5)});
89
myPath.AddRectangle (new Rectangle (33, 43, 20, 20)); e.Graphics.DrawPath (Pens.Black, myPath);
}
s6J ;IC5KHK@I8M JIUI867865D;H6@MO U5I•Dc;MO C6HK:9;8, 859JI @5Kc;K 56BJM8M O6U6 ;I 7865D;HM D ;ILM7I8M @DCL6@DC;MO H6C. QI78KL;MO :986C 56BDJ’r L5M C5KHK@I;;D 9?DL7, j6 ;9 @:DjIr8T7F ;I 6C;DO 7865D;bD, ;I C@D 7865D;HM:
bool FirstPagePrinted = false;
/ / w9O :986C L6@M;;I 6J56JM8M L6CDF PrintPage public void PrintBigEllipse (object sender, System. Drawing. Print ing. PrintPageEventArgs e)
{
if (FirstPagePrinted == false)
{
FirstPagePrinted = true: e. HasMorePages = true;
e.Graphics. DrawEllipse (Pens. Black, new Rectangle (0,0, e.PageBounds. Width, e. PageBounds. Height * 2));
else
e. HasMorePages = false; FirstPagePrinted = false;
e. Graphics, DrawEllipse (Pens. Black, new Rectangle (0, - (E. PageBounds. Height), e. PageBounds. Width,
e.PageBounds. Height * 2));
-
K FirstPagePrinted. (: d
. u o , n
( ( n false. 5 -
( n , KK
( , o 9
.
'
: 9 n , , —
K Graphics.DrawString. u ,
9 d, , 9'n Brush -
, :
Font myfont = new Font ("Batang", 36, FontStyle. Regular,GraphicsUnit. Pixel);
string Hello=”Hello World!”; e.Graphics.DrawString(Hello,myfont,Brushes.Black,30,30);
'. ' ,
( : 9- ,
( , 9.
90
F # )( ! # '
A 9 , 9
, 9 , 9 Kn (
. ” 9 , -
n 9 ( Kn -
) d. ' ( 9-
( 9, ( d
d. 5 n
myStrings:
//wF B:D;;I @DC789_Kr L686c;MO 9?9:9;8 :I7M@K.
//s6J K;MH;K8M D;DbDI?DBIbDG bDrG B:D;;6G L5M C5KbD H6_;6G
//E865D;HM, 7?DC 6U6?6eK@I8M L6BI 6J56J;MHI L6CDG PrintPage. int ArrayCounter = 0;
//w9 6J56J;MH L6CDG PrintDocument.PrintPage. [D; L5MLK7HIr,
//s6 5FCH6@MO :I7M@ B D:'F: myStrings () @_9 6U6?6e9;MO D BIL6@;9- ;MO,
//q 8IH6_ j6 D;DbDI?DB6@I;MO 6J'rH8 myFont, j6 L59C78I@?Fr
//fJ5I;MO C?F C5KHK e5M•8.
private void PrintStrings (object sender, PrintPageEventArgs e)
{
// fU6?67M8M B:D;;D, H95K<cM :D_7856H6@M:M
// y;895@I?I:M C6HK:9;8I ;I 7865D;HM. float LeftMargin = e.MarginBounds.Left; float TopMargin = e.MarginBounds.Top; float MyLines = 0;
float YPosition = 0; int Counter = 0; string CurrentLine;
// 4DC5ISK@I8M HD?THD78T 5FCHD@ ;I 7865D;bD.
MyLines = e.MarginBounds.Height /myFont.GetHeight (e.Graphics); // A6BC5KHK@I8M @7D 5FCHM •IO?K, BKLM;F<cM7T @ HD;bD 7865D;6H. while (Counter <MyLines && ArrayCounter <=mySt rings.GetUpperBound
())
{
CurrentLine = myStrings [ArrayCounter];
YPosition = TopMargin + Counter *myFont.GetHeight (e.Graphics); e.Graphics.DrawString (CurrentLine, myFont, Brushes.Black, LeftMargin, YPosition, new StringFormat();
Counter ++; ArrayCounter ++;
// tHj6 ;IC5KH6@I;D j9 ;9 @7D 5FCHM, 86 C5KHK@I8M ;I78KL;K 7865D;HK, if (!(ArrayCounter == myStrings.GetUpperBound (0)))
e.HasMorePages = true; else
e.HasMorePages = false;