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

Графіка

private void panel1_Paint(object sender, PaintEventArgs e)   // Form1_Paint, button1_Click
{

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);  

}




System.Drawing.Graphics g;
g = this.CreateGraphics();
Pen myPen = new Pen(System.Drawing.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);
}


Додати текст

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



Color.FromArgb(255, 192, 0);