Procedura: disegnare una curva in un Form

Aggiornamento: novembre 2007

Nell'esempio riportato di seguito vengono illustrati vari modi per disegnare curve su un form.

Esempio

System.Drawing.Graphics formGraphics = this.CreateGraphics();
System.Drawing.Pen myPen;
myPen = new System.Drawing.Pen(System.Drawing.Color.Black);

// Draw head with an ellipse.
formGraphics.DrawEllipse(myPen, 0, 0, 200, 200);

// Draw winking eye with an arc.
formGraphics.DrawArc(myPen, 40, 40, 40, 40, 180, -180);

// Draw open eye with an ellipse.
formGraphics.DrawEllipse(myPen, 120, 40, 40, 40);

// Draw nose with a Bezier spline.
formGraphics.DrawBezier(myPen, 100, 60, 120, 100, 90, 120, 80, 100);

// Draw mouth with a canonical spline.
Point[] apt = new Point[4];
apt[0] = new Point(60, 140);
apt[1] = new Point(140, 140);
apt[2] = new Point(100, 180);
apt[3] = new Point(60, 140);
formGraphics.DrawCurve(myPen, apt, 0, 3, 0.9f);

myPen.Dispose();
formGraphics.Dispose();

Compilazione del codice

L'esempio presenta i seguenti requisiti:

  • Un progetto Applicazione Windows Forms con un modulo denominato formGraphics.

Il codice deve trovarsi nell'ambito della classe Form. L'istanza del form è rappresentata da this.

Programmazione efficiente

È sempre necessario chiamare il metodo Dispose sugli oggetti che richiedono un notevole utilizzo delle risorse di sistema, quali gli oggetti Brush e Graphics.

Vedere anche

Concetti

Progettazione di un'interfaccia utente in Visual C#

Altre risorse

Creazione di testo e grafica

Presentazione guidata di Visual C#