.


:




:

































 

 

 

 





System.Drawing − :

() − Point PointF

− Size SizeF

− Rectangle RectangleF.

F , , ( F), , (float).

 

 

Size

 

Size , , Width Height, , . Size, :

 

Size sz = new Size();

 

Width Height .

, , :

sz.Width = 40;

sz.Height = 60;

:

public Size(int, int);

public Size(Point);

, , -:

Size sz1= new Size(10,20); // sz1.Width = 10, sz1.Height = 20 Size sz2 = new Size(15,50); // sz2.Width = 15, sz2.Height = 50

Point

Point X Y , , , .

pt :

 

Point pt = new Point();

X Y.

, , :

pt.X =25;

pt.Y=75;

Point, ,

:

 

public Point(Size);

public Point(int, int);

 

:

 

Point pt1 = new Point(10,20); // pt1.X =10, pt1.Y=20

Size sz = new Size(27,45);

Point pt2 = new Point(sz); // pt2.X=27, pt2.Y=45

 

:

 

public void Offset( int dx, int dy ); :X=X+dx Y=Y+dy;

Rectangle

 

. , , , , .

:

public Rectangle(

int x, // x-

int y, // y-

int width, //

int height //

);

 

public Rectangle(

Point location, //

Size size //

);

 

:

 

Point pt = new Point(10,15);

Size sz = new Size (50,70);

Rectangle rct = new Rectangle(pt,sz);

Rectangle rect = new Rectangle(20,20,50,30);

 

Rectangle . .

:

public void Intersect(Rectangle);

 

, , . , .

:

 

Rectangle rect,rct;

rect = new Rectangle(20,25,50,55);

rct = new Rectangle(10,10,30,40);

rect.Intersect(rct);

 

, rect :

 

X=20, Y=25, Width=20, Height=25.

 

:

 

public static Rectangle Union(Rectangle a, Rectangle b);

 

, , a b.

public void Offset(Point pos) public void Offset(int x, int y) , .

 

 

 

System.Drawing.Color.

:

 

public static Color.FromArgb(int red, int green, int blue);

 

red, green blue , . 0 255. 224 .

FromArgb:

 

public static Color FromArgb(int alpha, Color cr);

public static Color FromArgb(int alpha, int red, int green, int blue);

 

alpha . , . alpha 0 255. 0 (), 255 − () .

Color 200 , . , , − , WEB .

:

Color clr2 = Color.Beige; //

Color clr3 = Color.Magenta; //

Color clr4 = Color.Orange; //

 

 

.

System.Drawing.SolidBrush, :

Brush br2 = new SolidBrush(Color.Magenta);

Brush br3 = new SolidBrush(Color.FromArgb(200,10,120));

 

color public SolidBrush(Color color)

SolidBrush .

System.Drawing.Brushes , . :

 

Brush brr = Brushes.Orange;

 

System.Drawing.Drawing2D.HatchBrush .

:

 

public HatchBrush(HatchStyle hatchstyle, Color foreColor, Color backColor);

public HatchBrush(HatchStyle hatchstyle, Color foreColor);

 

:

 

foreColor − ;

backColor − ( − );

hatchstyle − .

 

, :

 

Cross − ;

DiagonalCross − ;

Horizontal − ;

Vertical − .

 

, :

 

Brush br1 = new HatchBrush(HatchStyle.Vertical,Color.Blue,Color.Beige);

 

System.Drawing.Pen.

:

 

public Pen(Color color);

public Pen(Color color, float width);

public Pen(Brush brush);

public Pen(Brush brush, float width);

 

:

 

color − ;

width − ;

brush −.

 

:

 

Pen pn = new Pen(Color. Magenta);

Pen pn1 = new Pen(Color.Orange,5);

Pen pn2 = new Pen(Brushes.Orange);

Pen pn3 = new Pen(Brushes.Magenta,10);

Pen pn4 = new Pen(Color.FromArgb(125,155, 0));

Pen pn5 = new Pen(Color.FromArgb(25,155,200),10);

 

System.Drawing.Pens , . :

 

Pen pn6 = Pens.Brown;

Pen pn7 = Pens.Magenta;

 

 

 

.

.NET () System.Drawing.Graphics. Graphics CreateGraphics(), Graphics:

 

Graphics dc = CreateGraphics();

 

dc , .

Graphics , . .

:

 

public void DrawRectangle(Pen pen, Rectangle rect);

public void DrawRectangle(Pen pen, int x, int y, int width, int height);

public void DrawRectangle(Pen pen, float x, float y, float width, float height);

 

:

 

public void DrawEllipse (Pen pen, Rectangle rect);

public void DrawEllipse (Pen pen, int x, int y, int width, int height);

public void DrawEllipse (Pen pen, float x, float y, float width, float height);

 

:

 

public void FillEllipse(Brush brush, Rectangle rect);

public void FillEllipse(Brush brush, int x, int y, int width, int height);

public void FillEllipse(Brush brush, float x, float y, float width, float height);

public void FillRectangle(Brush brush, Rectangle rect);

public void FillRectangle(Brush brush, int x, int y, int width, int height);

public void FillRectangle(Brush brush, float x, float y, float width, float height);

 

:

pen − ;

brush − ;

rect − ;

− ;

y − ;

width − ;

height − ;

 

:

 

public void DrawLine(Pen pen, Point pt1, Point pt2);

public void DrawLine(Pen pen, PointF pt1, PointF pt2);

public void DrawLine(Pen pen, int x1, int y1, int x2, int y2);

public void DrawLine(Pen pen, float x1, float y1, float x2, float y2);

 

:

pen − ;

pt1 − ;

pt2 − ;

1 1 − ;

2 2 − ;

 

:

 

dc.DrawRectangle(Pens.OrangeRed,5,10,25,45);

dc.DrawEllipse(Pens.Magenta,100,125,20,15);

dc.FillEllipse(Brushes.BlueViolet,45,50,20,15);

dc.DrawLine(Pens.Green,20,40,60,70);

 

DrawString. DrawString:

public void DrawString(string s, Font fnt, Brush br, PointF pt);

public void DrawString(string s, Font fnt, Brush br, RectangleF ltRct);

:

s ,

fnt ,

br ,

pt , ,

ltRct , , , () .

:

Font fnt = new Font("Arial",10); // Arial, 10

dc.DrawString("!",fnt, Brushes.Green,10,20);

 

1. , , .

Windows Application. MouseDown, . - , :

 

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

{

Graphics dc = CreateGraphics();

Font fnt = new Font("Coyrier",10);

if(e.Button.ToString()== "Left")

{

dc.DrawRectangle(Pens.OrangeRed,e.X,e.Y,15,15);

dc.DrawString("X="+e.X.ToString()+" Y="+e.Y.ToString(),fnt,Brushes.Green,e.X,e.Y+20);

}

if(e.Button.ToString()== "Right")

{

dc.DrawEllipse(Pens.Magenta,e.X,e.Y,20,15);

dc.FillEllipse(Brushes.Blue,e.X,e.Y,20,15);

}

}

. .

 





:


: 2016-11-02; !; : 420 |


:

:

,
==> ...

1885 - | 1804 -


© 2015-2024 lektsii.org - -

: 0.052 .