AllTheTimeWorld.com

csharp drawingDrawing Strings

Drawing Strings

Drawing Strings

Draw Filled Circle with Border

We will use a brush to draw a string at the point clicked.

Add this code to the MouseClick event:

private void Form1_MouseClick(object sender, MouseEventArgs e)
{
   // Draw strung Hello at the point clicked.
   // Get the graphics of the form.
   Graphics g = this.CreateGraphics();
   // Create a Blue Brush.
   SolidBrush myBrush = new SolidBrush(Color.Blue);
   // Use the Font of the form.
   g.DrawString("Hello", this.Font, myBrush, e.X, e.Y);
}
To Do: Experiment! Try drawing a string inside a shape. Create an array of words and select one randomly from the array.