Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Drawing objects on a form
Message
From
04/07/2001 04:49:39
 
 
To
02/07/2001 15:38:07
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00526033
Message ID:
00526609
Views:
14
Dan,

Forms are derived from lots of classes, one being Control. The Control class inherits a property called Handle from Control, this is the HWND for the form and can be used for whatever purpose.

The easiest way to use the Graphics class is to respond to override the OnPaint handler (the same as handling the WM_PAINT message). The PaintEventArgs parameter is an object containing two properties, Graphics and ClipRectangle which can then be used something like this.
using System;
using System.WinForms;
using System.Drawing;

public class SampleForm : Form
{
   public SampleForm()
   {
      // Update the title bar.
      Text = "Drawing Demo";
   }

   protected override void OnPaint(PaintEventArgs e)
   {
      e.Graphics.DrawString("Sample Text", Font, new SolidBrush(Color.Black), ClientRectangle);
   }

   public static void Main(string[] args)
   {
      Application.Run(new SampleForm());
   }
}
HTH
Neil
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform