Головна‎ > ‎C# WinForms‎ > ‎

Графіка

using System.Drawing;


panel1

private void panel1_Paint(object sender, PaintEventArgs e)   
{

Graphics g = panel1.CreateGraphics();

Brush green = new SolidBrush(Color.Green);
Pen greenPen = new Pen(green, 4);

g.DrawLine(greenPen, 10, 10, 200, 200); 

Point[] p = new Point[3];
p[0] = new Point(200, 10);
p[1] = new Point(150, 75);
p[2] = new Point(250, 75);
g.DrawPolygon(greenPen, p);  

}




Form1_Paint,  button1_Click,  timer1_Tick

Graphics g;
g = this.CreateGraphics();
Pen myPen = new Pen(Color.Red, 5);
g.DrawLine(myPen, 20, 20, 200, 200);
 




DrawEllipse(Pen, x, y, width, height);

Clear(Color.Green);  // заливка




Крива Безьє

private void DrawBezierPoint(PaintEventArgs e)
{
    Pen blackPen = new Pen(Color.Black, 3);

    Point start = new Point(100, 100);
    Point control1 = new Point(200, 10);
    Point control2 = new Point(350, 50);
    Point end = new Point(500, 100);

    // Намалювати арку
    e.Graphics.DrawBezier(blackPen, start, control1, control2, end);
}




Додати текст

Font drawFont = new Font("Arial", 16);
StringFormat drawFormat = new StringFormat();
g.DrawString("12345", drawFont, new SolidBrush(Color.Red), 50, 50, drawFormat);





Color.FromArgb(255, 192, 0);    // колір