Hi, I am trying to do some tricks with buttons and labels. I want to use the paint event to do drawing on a button or label when it is painted. I am trying to use the PaintEventHandler to do this. In the constructor for my form I added two PaintEventHandler delegates, one for the form and one for the label. The Form delegate works fine, it prints the message “Hello mum” in nice large red letters on the form. The one for the delegate doesn’t (as far as I can tell). The label simply draws with its default text (“label1”). The code is shown below. Any ideas??
public Form1()
{ // // Required for Windows Form Designer support // InitializeComponent();
// My test this.Paint +=new PaintEventHandler(Form1_Paint); this.label1.Paint +=new PaintEventHandler(label1_Paint); // }
private static void Form1_Paint(object sender , PaintEventArgs e) { // Get graphics object Graphics g = e.Graphics;
g.DrawString("Hello Mum!",new Font("Verdana",20,FontStyle.Regular),new SolidBrush(Color.Tomato),40,40); }
private static void label1_Paint(object sender , PaintEventArgs e) { // Get graphics object Graphics g = e.Graphics; Font fnt = new Font("Veranda",20,FontStyle.Regular);
g.DrawString("Hello Mum!",new Font("Verdana",20,FontStyle.Regular),new SolidBrush(Color.Tomato),1,1); } Thanks, Keith Stallings
|