home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Edit List and Spin / TextBoxDemo / TextBoxDemo.cs next >
Encoding:
Text File  |  2001-01-15  |  1.2 KB  |  43 lines

  1. //------------------------------------------
  2. // TextBoxDemo.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class TextBoxDemo: Form
  9. {
  10.      Label label;
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new TextBoxDemo());
  15.      }
  16.      public TextBoxDemo()
  17.      {
  18.           Text = "TextBox Demo";
  19.  
  20.                // Create text box control.
  21.  
  22.           TextBox txtbox     = new TextBox();
  23.           txtbox.Parent      = this;
  24.           txtbox.Location    = new Point(Font.Height, Font.Height);
  25.           txtbox.Size        = new Size(ClientSize.Width - 2 * Font.Height,
  26.                                         Font.Height);
  27.           txtbox.Anchor      |= AnchorStyles.Right;
  28.           txtbox.TextChanged += new EventHandler(TextBoxOnTextChanged);
  29.  
  30.                // Create label control.
  31.  
  32.           label          = new Label();
  33.           label.Parent   = this;
  34.           label.Location = new Point(Font.Height, 3 * Font.Height);
  35.           label.AutoSize = true;
  36.      }
  37.      void TextBoxOnTextChanged(object obj, EventArgs ea)
  38.      {
  39.           TextBox txtbox = (TextBox) obj;
  40.  
  41.           label.Text = txtbox.Text;
  42.      }
  43. }