Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Drawing objects on a form
Message
De
04/07/2001 04:49:39
 
 
À
02/07/2001 15:38:07
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00526033
Message ID:
00526609
Vues:
15
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform