Graphics g = Graphics.FromHwnd(this.Handle); Pen pen = new Pen(Color.Black); g.DrawLine(pen, 10, 10, 100, 100);
Graphics g = CreateGraphics(); Brush brush = new SolidBrush(Color.Red); g.FillRectangle(brush, 20, 20, 50, 50);
Graphics g = CreateGraphics(); Font font = new Font("Arial", 12); SolidBrush brush = new SolidBrush(Color.Black); g.DrawString("Hello world", font, brush, new PointF(20, 20));This code creates a Graphics object from the current form and then draws the text "Hello world" using a specified font and color at a specified position. These examples are using the System.Drawing namespace in C# which is part of the .NET framework.