home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Hello Windows Forms / PaintTwoForms / PaintTwoForms.cs next >
Encoding:
Text File  |  2001-01-15  |  1.1 KB  |  42 lines

  1. //--------------------------------------------
  2. // PaintTwoForms.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class PaintTwoForms
  9. {
  10.      static Form form1, form2;
  11.  
  12.      public static void Main()
  13.      {
  14.           form1 = new Form();
  15.           form2 = new Form();
  16.  
  17.           form1.Text      = "First Form";
  18.           form1.BackColor = Color.White;
  19.           form1.Paint    += new PaintEventHandler(MyPaintHandler);
  20.  
  21.           form2.Text      = "Second Form";
  22.           form2.BackColor = Color.White;
  23.           form2.Paint    += new PaintEventHandler(MyPaintHandler);
  24.           form2.Show();
  25.  
  26.           Application.Run(form1);
  27.      }
  28.      static void MyPaintHandler(object objSender, PaintEventArgs pea)
  29.      {
  30.           Form     form = (Form)objSender;
  31.           Graphics grfx = pea.Graphics;
  32.           string   str;
  33.  
  34.           if(form == form1)
  35.                str = "Hello from the first form";
  36.           else
  37.                str = "Hello from the second form";
  38.  
  39.           grfx.DrawString(str, form.Font, Brushes.Black, 0, 0);
  40.      }
  41. }
  42.