Csharp/C Sharp by API/System.Windows.Forms/Label

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Label.Background

  
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
      private System.Windows.Forms.Button learnMoreButton;
      private System.Windows.Forms.Label label2;
      private System.Windows.Forms.Label label1;
      
      public Form1() {
        InitializeComponent();
      }
      private void InitializeComponent()
      {
         this.learnMoreButton = new System.Windows.Forms.Button();
         this.label2 = new System.Windows.Forms.Label();
         this.label1 = new System.Windows.Forms.Label();
         this.SuspendLayout();
         // 
         // learnMoreButton
         // 
         this.learnMoreButton.Font = new System.Drawing.Font( "Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
         this.learnMoreButton.Location = new System.Drawing.Point( 17, 81 );
         this.learnMoreButton.Name = "learnMoreButton";
         this.learnMoreButton.Size = new System.Drawing.Size( 120, 59 );
         this.learnMoreButton.TabIndex = 11;
         this.learnMoreButton.Text = "Learn More";
         // 
         // label2
         // 
         this.label2.BackColor = System.Drawing.Color.LightYellow;
         this.label2.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
         this.label2.Font = new System.Drawing.Font( "Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
         this.label2.ForeColor = System.Drawing.Color.MidnightBlue;
         this.label2.Location = new System.Drawing.Point( 17, 154 );
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size( 273, 25 );
         this.label2.TabIndex = 10;
         this.label2.Text = "text";
         this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         // 
         // label1
         // 
         this.label1.BackColor = System.Drawing.Color.LightYellow;
         this.label1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
         this.label1.Font = new System.Drawing.Font( "Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ( ( byte ) ( 0 ) ) );
         this.label1.ForeColor = System.Drawing.Color.MidnightBlue;
         this.label1.Location = new System.Drawing.Point( 17, 17 );
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size( 273, 47 );
         this.label1.TabIndex = 9;
         this.label1.Text = "test";
         this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
         // 
         // VisualInheritanceForm
         // 
         this.AutoScaleDimensions = new System.Drawing.SizeF( 6F, 13F );
         this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
         this.ClientSize = new System.Drawing.Size( 307, 201 );
         this.Controls.Add( this.learnMoreButton );
         this.Controls.Add( this.label2 );
         this.Controls.Add( this.label1 );
         this.Name = "VisualInheritanceForm";
         this.Text = "Visual Inheritance";
         this.ResumeLayout( false );
      }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new Form1());
    }
}


Label.Click

 
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class LabelWithGenericEvent : System.Windows.Forms.Form
{
  private System.Windows.Forms.Label lblTitle;
  public LabelWithGenericEvent()
  {
    InitializeComponent();
  }
  private void InitializeComponent()
  {
    this.lblTitle = new System.Windows.Forms.Label();
    this.SuspendLayout();
    // 
    // lblTitle
    // 
    this.lblTitle.Location = new System.Drawing.Point(40, 24);
    this.lblTitle.Name = "lblTitle";
    this.lblTitle.Size = new System.Drawing.Size(150, 25);
    this.lblTitle.TabIndex = 0;
    this.lblTitle.Text = "Events Demonstrator";
    this.lblTitle.Click += new System.EventHandler(this.GenericEventHandler);
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(242, 173);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {  this.lblTitle});
    this.ResumeLayout(false);
  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new LabelWithGenericEvent());
  }
  private void GenericEventHandler(object sender, EventArgs e)
  {
    MessageBox.Show("Generic event handler","Event Demo");
  }
}


Label.DataBindings

 
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
   public class Form1 : System.Windows.Forms.Form {
      private System.Windows.Forms.Label label1;
      private System.Windows.Forms.Label label2;
      private System.Data.DataSet dataSet1;
 
      private System.ruponentModel.Container components = null;
      public Form1(){ 
 
         InitializeComponent();
      }
      private void InitializeComponent() {
         this.label1 = new System.Windows.Forms.Label();
         this.label2 = new System.Windows.Forms.Label();
         this.dataSet1 = new System.Data.DataSet();
         ((System.ruponentModel.ISupportInitialize)(this.dataSet1)).BeginInit();
         this.SuspendLayout();
 
         this.label1.Location = new System.Drawing.Point(16, 8);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(72, 16);
         this.label1.TabIndex = 0;
         this.label1.Text = "label1";
 
         this.label2.Location = new System.Drawing.Point(16, 40);
         this.label2.Name = "label2";
         this.label2.Size = new System.Drawing.Size(72, 16);
         this.label2.TabIndex = 1;
         this.label2.Text = "label2";
 
         this.dataSet1.DataSetName = "NewDataSet";
         this.dataSet1.Locale = new System.Globalization.CultureInfo("en-GB");
 
         this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
         this.ClientSize = new System.Drawing.Size(128, 69);
         this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                      this.label2,
                                                                      this.label1});
         this.Name = "Form1";
         this.Text = "Form1";
         this.Load += new System.EventHandler(this.Form1_Load);
         ((System.ruponentModel.ISupportInitialize)(this.dataSet1)).EndInit();
         this.ResumeLayout(false);
      }
 
      static void Main() {
         Application.Run(new Form1());
      }
      private void Form1_Load(object sender, System.EventArgs e) {
         string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
    
         string SQL = @"select * from employee";
         SqlConnection Conn = new SqlConnection(connString);
         SqlDataAdapter da = new SqlDataAdapter(SQL, Conn);
         da.Fill(dataSet1, "employee");
         // Bind the Label"s Text property to the ProductID of the Products table
         label1.DataBindings.Add("Text", dataSet1, "employee.ID");
         // Bind the second label"s Text property to the UnitPrice column
         label2.DataBindings.Add("Text", dataSet1, "employee.firstname");
      }
   }


Label.DoDragDrop

   

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald
Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
    /// <summary>
    /// Summary description for ControlPalette.
    /// </summary>
    public class ControlPalette : System.Windows.Forms.Form
    {
        internal System.Windows.Forms.ImageList images;
        internal System.Windows.Forms.Label lblPictureThree;
        internal System.Windows.Forms.Label lblPictureTwo;
        internal System.Windows.Forms.Label lblPictureOne;
        private System.ruponentModel.IContainer components;
        public ControlPalette()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if(components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }
        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.ruponents = new System.ruponentModel.Container();
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(ControlPalette));
            this.images = new System.Windows.Forms.ImageList(this.ruponents);
            this.lblPictureThree = new System.Windows.Forms.Label();
            this.lblPictureTwo = new System.Windows.Forms.Label();
            this.lblPictureOne = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // images
            // 
            this.images.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
            this.images.ImageSize = new System.Drawing.Size(16, 16);
            this.images.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("images.ImageStream")));
            this.images.TransparentColor = System.Drawing.Color.Transparent;
            // 
            // lblPictureThree
            // 
            this.lblPictureThree.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.lblPictureThree.Image = ((System.Drawing.Bitmap)(resources.GetObject("lblPictureThree.Image")));
            this.lblPictureThree.ImageIndex = 2;
            this.lblPictureThree.ImageList = this.images;
            this.lblPictureThree.Location = new System.Drawing.Point(8, 112);
            this.lblPictureThree.Name = "lblPictureThree";
            this.lblPictureThree.Size = new System.Drawing.Size(56, 48);
            this.lblPictureThree.TabIndex = 3;
            this.lblPictureThree.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
            // 
            // lblPictureTwo
            // 
            this.lblPictureTwo.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.lblPictureTwo.Image = ((System.Drawing.Bitmap)(resources.GetObject("lblPictureTwo.Image")));
            this.lblPictureTwo.ImageIndex = 1;
            this.lblPictureTwo.ImageList = this.images;
            this.lblPictureTwo.Location = new System.Drawing.Point(8, 60);
            this.lblPictureTwo.Name = "lblPictureTwo";
            this.lblPictureTwo.Size = new System.Drawing.Size(56, 48);
            this.lblPictureTwo.TabIndex = 2;
            this.lblPictureTwo.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
            // 
            // lblPictureOne
            // 
            this.lblPictureOne.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
            this.lblPictureOne.Image = ((System.Drawing.Bitmap)(resources.GetObject("lblPictureOne.Image")));
            this.lblPictureOne.ImageIndex = 0;
            this.lblPictureOne.ImageList = this.images;
            this.lblPictureOne.Location = new System.Drawing.Point(8, 8);
            this.lblPictureOne.Name = "lblPictureOne";
            this.lblPictureOne.Size = new System.Drawing.Size(56, 48);
            this.lblPictureOne.TabIndex = 1;
            this.lblPictureOne.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lbl_MouseDown);
            // 
            // ControlPalette
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(76, 174);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.lblPictureThree,
                                                                          this.lblPictureTwo,
                                                                          this.lblPictureOne});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
            this.Name = "ControlPalette";
            this.Text = "Pictures";
            this.ResumeLayout(false);
        }
        #endregion
        private void lbl_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            Label lbl = (Label)sender;
            lbl.DoDragDrop(lbl.Image, DragDropEffects.Copy);
        }
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main() 
        {
            Application.Run(new ControlPalette());
        }
    }


Label.Image

 
using System;        
using System.Drawing;
using System.Windows.Forms;
public class LabelImageAdding : Form
{
  Label lblEcho;
  TextBox txt;
  public LabelImageAdding()
  {
    Size = new Size(300,250);
    lblEcho = new Label();
    lblEcho.Parent = this;
    lblEcho.Text = "test";
    lblEcho.Location = new Point(0,0);
    lblEcho.AutoSize = true;
    lblEcho.BorderStyle = BorderStyle.Fixed3D;
    int yDelta = lblEcho.Height + 10;
    
    Image img = Image.FromFile("YourFile.bmp");
    Label lblImage = new Label();
    lblImage.Parent = this;
    lblImage.Location = new Point(250, 0);
    lblImage.Image = img;
    lblImage.Anchor = AnchorStyles.Top | AnchorStyles.Right;
    lblImage.Size = new Size(img.Width, img.Height);
    Label lblCaption = new Label();
    lblCaption.Parent = this;
    lblCaption.Text = "&Enter Text Here:";
    lblCaption.Size = new Size(lblCaption.PreferredWidth, lblCaption.PreferredHeight);
    lblCaption.Location = new Point(0, yDelta);
    lblCaption.BorderStyle = BorderStyle.FixedSingle;
    txt = new TextBox();
    txt.Parent = this;
    txt.Size = new Size(100,23);
    txt.Location = new Point(lblCaption.Width + 5, yDelta);
    txt.TextChanged += new System.EventHandler(txt_TextChanged);
  }
  static void Main() 
  {
    Application.Run(new LabelImageAdding());
  }
  private void txt_TextChanged(object sender, EventArgs e)
  {
    lblEcho.Text = txt.Text;
  }
}


Label.ImageAlign

  

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
public class ImageLists : Form
{
  ImageList imgList;
  Label lbl;
  LinkLabel lnk;
  Button btn;
  public ImageLists()
  {
       Size = new Size(300,300);
    imgList = new ImageList();
    Image img;
    String[] arFiles = {"1.ico","2.ico","3.ico"};

    for (int i = 0; i < arFiles.Length; i++)
    {
      img = Image.FromFile(arFiles[i]);
      imgList.Images.Add(img);
    }
    imgList.ImageSize = new Size(32, 32);

    lbl = new Label();
       lbl.Parent = this;
       lbl.Text = "Label";
       lbl.Location = new Point(0,0);
       lbl.Size = new Size(lbl.PreferredWidth + imgList.ImageSize.Width, 
      imgList.ImageSize.Height + 10);
       lbl.BorderStyle = BorderStyle.Fixed3D;
    lbl.ImageList = imgList;
    lbl.ImageIndex = 0;
    lbl.ImageAlign = ContentAlignment.MiddleRight;
       int yDelta = lbl.Height + 10;
     
       lnk = new LinkLabel();
       lnk.Parent = this;
       lnk.Text = "LinkLabel";
       lnk.Size = new Size(lnk.PreferredWidth + imgList.ImageSize.Width, 
      imgList.ImageSize.Height + 10);
       lnk.Location = new Point(0, yDelta);
    lnk.ImageList = imgList;
    lnk.ImageIndex = 0;
    lnk.ImageAlign = ContentAlignment.MiddleRight;
    btn = new Button();
    btn.Parent = this;
    btn.ImageList = imgList;
    btn.ImageIndex = imgList.Images.Count - 1;
    btn.Location = new Point(0, 2 * yDelta);
    btn.Size = new Size(3 * imgList.ImageSize.Width, 
              2 * imgList.ImageSize.Height);

    lbl.ImageIndex = 1;
    lnk.ImageIndex = 0;
    btn.ImageIndex = 2;
  }
  static void Main() 
  {
      Application.Run(new ImageLists());
  }
}


Label.ImageIndex

  

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
public class ImageLists : Form
{
  ImageList imgList;
  Label lbl;
  LinkLabel lnk;
  Button btn;
  public ImageLists()
  {
       Size = new Size(300,300);
    imgList = new ImageList();
    Image img;
    String[] arFiles = {"1.ico","2.ico","3.ico"};

    for (int i = 0; i < arFiles.Length; i++)
    {
      img = Image.FromFile(arFiles[i]);
      imgList.Images.Add(img);
    }
    imgList.ImageSize = new Size(32, 32);

    lbl = new Label();
       lbl.Parent = this;
       lbl.Text = "Label";
       lbl.Location = new Point(0,0);
       lbl.Size = new Size(lbl.PreferredWidth + imgList.ImageSize.Width, 
      imgList.ImageSize.Height + 10);
       lbl.BorderStyle = BorderStyle.Fixed3D;
    lbl.ImageList = imgList;
    lbl.ImageIndex = 0;
    lbl.ImageAlign = ContentAlignment.MiddleRight;
       int yDelta = lbl.Height + 10;
     
       lnk = new LinkLabel();
       lnk.Parent = this;
       lnk.Text = "LinkLabel";
       lnk.Size = new Size(lnk.PreferredWidth + imgList.ImageSize.Width, 
      imgList.ImageSize.Height + 10);
       lnk.Location = new Point(0, yDelta);
    lnk.ImageList = imgList;
    lnk.ImageIndex = 0;
    lnk.ImageAlign = ContentAlignment.MiddleRight;
    btn = new Button();
    btn.Parent = this;
    btn.ImageList = imgList;
    btn.ImageIndex = imgList.Images.Count - 1;
    btn.Location = new Point(0, 2 * yDelta);
    btn.Size = new Size(3 * imgList.ImageSize.Width, 
              2 * imgList.ImageSize.Height);

    lbl.ImageIndex = 1;
    lnk.ImageIndex = 0;
    btn.ImageIndex = 2;
  }
  static void Main() 
  {
      Application.Run(new ImageLists());
  }
}


Label.ImageList

  

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
public class ImageLists : Form
{
  ImageList imgList;
  Label lbl;
  LinkLabel lnk;
  Button btn;
  public ImageLists()
  {
       Size = new Size(300,300);
    imgList = new ImageList();
    Image img;
    String[] arFiles = {"1.ico","2.ico","3.ico"};

    for (int i = 0; i < arFiles.Length; i++)
    {
      img = Image.FromFile(arFiles[i]);
      imgList.Images.Add(img);
    }
    imgList.ImageSize = new Size(32, 32);

    lbl = new Label();
       lbl.Parent = this;
       lbl.Text = "Label";
       lbl.Location = new Point(0,0);
       lbl.Size = new Size(lbl.PreferredWidth + imgList.ImageSize.Width, 
      imgList.ImageSize.Height + 10);
       lbl.BorderStyle = BorderStyle.Fixed3D;
    lbl.ImageList = imgList;
    lbl.ImageIndex = 0;
    lbl.ImageAlign = ContentAlignment.MiddleRight;
       int yDelta = lbl.Height + 10;
     
       lnk = new LinkLabel();
       lnk.Parent = this;
       lnk.Text = "LinkLabel";
       lnk.Size = new Size(lnk.PreferredWidth + imgList.ImageSize.Width, 
      imgList.ImageSize.Height + 10);
       lnk.Location = new Point(0, yDelta);
    lnk.ImageList = imgList;
    lnk.ImageIndex = 0;
    lnk.ImageAlign = ContentAlignment.MiddleRight;
    btn = new Button();
    btn.Parent = this;
    btn.ImageList = imgList;
    btn.ImageIndex = imgList.Images.Count - 1;
    btn.Location = new Point(0, 2 * yDelta);
    btn.Size = new Size(3 * imgList.ImageSize.Width, 
              2 * imgList.ImageSize.Height);

    lbl.ImageIndex = 1;
    lnk.ImageIndex = 0;
    btn.ImageIndex = 2;
  }
  static void Main() 
  {
      Application.Run(new ImageLists());
  }
}


Label.Localtion

  
using System;
using System.Windows.Forms;
class MainForm : Form
{
    private Label label1;
    private TextBox textBox1;
    private Button button1;
    public MainForm()
    {
         this.label1 = new Label();
         this.textBox1 = new TextBox();
         this.button1 = new Button();
         this.SuspendLayout();
         this.label1.Location = new System.Drawing.Point(16, 36);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(128, 16);
         this.label1.TabIndex = 0;
         this.label1.Text = "Please enter your name:"; 
         this.textBox1.Location = new System.Drawing.Point(152, 32);
         this.textBox1.Name = "textBox1";
         this.textBox1.TabIndex = 1;
         this.textBox1.Text = "";
         this.button1.Location = new System.Drawing.Point(109, 80);
         this.button1.Name = "button1";
         this.button1.TabIndex = 2;
         this.button1.Text = "Enter";
         this.button1.Click += new System.EventHandler(this.button1_Click);
         this.ClientSize = new System.Drawing.Size(292, 126);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.textBox1);
         this.Controls.Add(this.label1);
         this.Name = "form1";
         this.Text = "Visual C#";
         this.ResumeLayout(false);
     }
     private void button1_Click(object sender, System.EventArgs e)
     {
        System.Console.WriteLine("User entered: " + textBox1.Text);
        MessageBox.Show("Welcome, " + textBox1.Text, "Visual C#");
     }
     [STAThread]
     public static void Main()
     {
        Application.EnableVisualStyles();
        Application.Run(new MainForm());
     }
}


Label.Margin

  
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.Button cmdSetText;
    private System.Windows.Forms.Button cmdSetTextConstraint;
  public Form1() {
        InitializeComponent();
  }
    private void InitializeComponent(){
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.label1 = new System.Windows.Forms.Label();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.cmdSetText = new System.Windows.Forms.Button();
        this.cmdSetTextConstraint = new System.Windows.Forms.Button();
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();
        // 
        // groupBox1
        // 
        this.groupBox1.AutoSize = true;
        this.groupBox1.Controls.Add(this.label1);
        this.groupBox1.Location = new System.Drawing.Point(15, 133);
        this.groupBox1.Margin = new System.Windows.Forms.Padding(20);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(200, 100);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "groupBox1";
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(17, 25);
        this.label1.Margin = new System.Windows.Forms.Padding(5);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(35, 13);
        this.label1.TabIndex = 0;
        this.label1.Text = "label1";
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(15, 12);
        this.textBox1.Multiline = true;
        this.textBox1.Name = "textBox1";
        this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
        this.textBox1.Size = new System.Drawing.Size(200, 47);
        this.textBox1.TabIndex = 1;
        this.textBox1.Text = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the l" +
            "azy dog.";
        // 
        // cmdSetText
        // 
        this.cmdSetText.Location = new System.Drawing.Point(50, 65);
        this.cmdSetText.Name = "cmdSetText";
        this.cmdSetText.Size = new System.Drawing.Size(165, 23);
        this.cmdSetText.TabIndex = 2;
        this.cmdSetText.Text = "Set Text";
        this.cmdSetText.UseVisualStyleBackColor = true;
        this.cmdSetText.Click += new System.EventHandler(this.cmdSetText_Click);
        // 
        // cmdSetTextConstraint
        // 
        this.cmdSetTextConstraint.Location = new System.Drawing.Point(50, 91);
        this.cmdSetTextConstraint.Name = "cmdSetTextConstraint";
        this.cmdSetTextConstraint.Size = new System.Drawing.Size(165, 23);
        this.cmdSetTextConstraint.TabIndex = 3;
        this.cmdSetTextConstraint.Text = "Constrain Label and Set Text";
        this.cmdSetTextConstraint.UseVisualStyleBackColor = true;
        this.cmdSetTextConstraint.Click += new System.EventHandler(this.cmdSetTextConstraint_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.AutoSize = true;
        this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this.ClientSize = new System.Drawing.Size(247, 336);
        this.Controls.Add(this.cmdSetTextConstraint);
        this.Controls.Add(this.cmdSetText);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.groupBox1);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Form1";
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    private void cmdSetText_Click(object sender, EventArgs e)
    {
        label1.MaximumSize = new Size(0,0);
        label1.Text = "";
        label1.Text = textBox1.Text;
    }
    private void cmdSetTextConstraint_Click(object sender, EventArgs e)
    {
        label1.MaximumSize = new Size(200,0);
        label1.Text = textBox1.Text;
    }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }
}


Label.MouseDown

  


using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
  internal System.Windows.Forms.Label lblDragger;
  public Form1()
  {
    this.lblDragger = new System.Windows.Forms.Label();
    this.SuspendLayout();
    this.lblDragger.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.lblDragger.Image = new Bitmap("winter.jpg");
    this.lblDragger.Location = new System.Drawing.Point(110, 105);
    this.lblDragger.Name = "lblDragger";
    this.lblDragger.Size = new System.Drawing.Size(72, 56);
    this.lblDragger.TabIndex = 2;
    this.lblDragger.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseUp);
    this.lblDragger.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseMove);
    this.lblDragger.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseDown);
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.lblDragger});
    this.Text = "Fake Drag And Drop";
    this.ResumeLayout(false);
  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new Form1());
  }

  private bool isDragging = false;

  private int clickOffsetX, clickOffsetY;

  private void lblDragger_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e)
  {
    isDragging = true;
    clickOffsetX = e.X;
    clickOffsetY = e.Y;
  }
  private void lblDragger_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e)
  {
    isDragging = false;
  }
  private void lblDragger_MouseMove(System.Object sender,
    System.Windows.Forms.MouseEventArgs e)
  {
    if (isDragging == true)
    {
      lblDragger.Left = e.X + lblDragger.Left - clickOffsetX;
      lblDragger.Top = e.Y + lblDragger.Top - clickOffsetY;
    }
  }
}


Label.MouseHover

   
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class frmMouseButtons : System.Windows.Forms.Form {
    private System.Windows.Forms.Label lblLeftClick;
    private System.Windows.Forms.Label lblRightClick;
    private System.Windows.Forms.Label lblMiddleClick;
    private System.Windows.Forms.Label lblHover;
    public frmMouseButtons() {
        this.lblLeftClick = new System.Windows.Forms.Label();
        this.lblRightClick = new System.Windows.Forms.Label();
        this.lblMiddleClick = new System.Windows.Forms.Label();
        this.lblHover = new System.Windows.Forms.Label();
        this.SuspendLayout();
        this.lblLeftClick.Location = new System.Drawing.Point(8, 8);
        this.lblRightClick.Location = new System.Drawing.Point(8, 32);
        this.lblRightClick.Size = new System.Drawing.Size(100, 32);
        this.lblMiddleClick.Location = new System.Drawing.Point(8, 72);
        this.lblHover.Location = new System.Drawing.Point(8, 104);
        this.lblHover.MouseEnter += new System.EventHandler(this.lblHover_MouseEnter);
        this.lblHover.MouseHover += new System.EventHandler(this.lblHover_MouseHover);
        this.lblHover.MouseLeave += new System.EventHandler(this.lblHover_MouseLeave);
        this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
        this.ClientSize = new System.Drawing.Size(184, 198);
        this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.lblHover,
                                      this.lblMiddleClick,
                                      this.lblRightClick,
                                      this.lblLeftClick});
        this.MaximizeBox = false;
        this.ResumeLayout(false);
    }
    protected override void OnMouseDown(MouseEventArgs e) {
        switch (e.Button) {
            case (MouseButtons.Left):
                lblLeftClick.Text = "Left Click";
                break;
            case (MouseButtons.Middle):
                lblLeftClick.Text = "Middle Click";
                break;
            case (MouseButtons.Right):
                lblLeftClick.Text = "Right Click";
                break;
            case (MouseButtons.XButton1):
                lblLeftClick.Text = "XButton1 Click";
                break;
            case (MouseButtons.XButton2):
                lblLeftClick.Text = "XButton2 Click";
                break;
        }
        switch (e.Clicks) {
            case 1:
                lblMiddleClick.Text = "Single Click";
                break;
            case 2:
                lblMiddleClick.Text = "Double Click!";
                break;
            default:
                lblMiddleClick.Text = "Many clicks!";
                break;
        }
    }
    protected override void OnMouseWheel(MouseEventArgs e) {
        switch (e.Delta) {
            case -360:
                lblRightClick.Text = "One Rotation Reverse";
                break;
            case -720:
                lblRightClick.Text = "Two Rotations Reverse";
                break;
            case 360:
                lblRightClick.Text = "One Rotation Forward";
                break;
            case 720:
                lblRightClick.Text = "Two Rotations Forward";
                break;
            default:
                lblRightClick.Text = "Rotation wasn"t full turn of wheel";
                break;
        }
    }

    protected void lblHover_MouseEnter(object sender, EventArgs e) {
        lblRightClick.Text = "One Rotation Forward";
        lblHover.Text = "Entering label";
        Cursor = Cursors.NoMove2D;
    }
    protected void lblHover_MouseHover(object sender, EventArgs e) {
        lblHover.Text = "Hovering over label";
        Cursor = Cursors.Hand;
        System.Diagnostics.Debug.WriteLine("hover");
    }
    protected void lblHover_MouseLeave(object sender, EventArgs e) {
        lblHover.Text = "Leaving label";
        Cursor = Cursors.Default;
    }
    [STAThread]
    static void Main() {
        Application.Run(new frmMouseButtons());
    }
}


Label.MouseMove

  

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
  internal System.Windows.Forms.Label lblDragger;
  public Form1()
  {
    this.lblDragger = new System.Windows.Forms.Label();
    this.SuspendLayout();
    this.lblDragger.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.lblDragger.Image = new Bitmap("winter.jpg");
    this.lblDragger.Location = new System.Drawing.Point(110, 105);
    this.lblDragger.Name = "lblDragger";
    this.lblDragger.Size = new System.Drawing.Size(72, 56);
    this.lblDragger.TabIndex = 2;
    this.lblDragger.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseUp);
    this.lblDragger.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseMove);
    this.lblDragger.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseDown);
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.lblDragger});
    this.Text = "Fake Drag And Drop";
    this.ResumeLayout(false);
  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new Form1());
  }

  private bool isDragging = false;

  private int clickOffsetX, clickOffsetY;

  private void lblDragger_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e)
  {
    isDragging = true;
    clickOffsetX = e.X;
    clickOffsetY = e.Y;
  }
  private void lblDragger_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e)
  {
    isDragging = false;
  }
  private void lblDragger_MouseMove(System.Object sender,
    System.Windows.Forms.MouseEventArgs e)
  {
    if (isDragging == true)
    {
      lblDragger.Left = e.X + lblDragger.Left - clickOffsetX;
      lblDragger.Top = e.Y + lblDragger.Top - clickOffsetY;
    }
  }
}


Label.MouseUp

  

using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
public class Form1 : System.Windows.Forms.Form
{
  internal System.Windows.Forms.Label lblDragger;
  public Form1()
  {
    this.lblDragger = new System.Windows.Forms.Label();
    this.SuspendLayout();
    this.lblDragger.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
    this.lblDragger.Image = new Bitmap("winter.jpg");
    this.lblDragger.Location = new System.Drawing.Point(110, 105);
    this.lblDragger.Name = "lblDragger";
    this.lblDragger.Size = new System.Drawing.Size(72, 56);
    this.lblDragger.TabIndex = 2;
    this.lblDragger.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseUp);
    this.lblDragger.MouseMove += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseMove);
    this.lblDragger.MouseDown += new System.Windows.Forms.MouseEventHandler(this.lblDragger_MouseDown);
    this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    this.ClientSize = new System.Drawing.Size(292, 266);
    this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                    this.lblDragger});
    this.Text = "Fake Drag And Drop";
    this.ResumeLayout(false);
  }
  [STAThread]
  static void Main() 
  {
    Application.Run(new Form1());
  }

  private bool isDragging = false;

  private int clickOffsetX, clickOffsetY;

  private void lblDragger_MouseDown(System.Object sender, System.Windows.Forms.MouseEventArgs e)
  {
    isDragging = true;
    clickOffsetX = e.X;
    clickOffsetY = e.Y;
  }
  private void lblDragger_MouseUp(System.Object sender, System.Windows.Forms.MouseEventArgs e)
  {
    isDragging = false;
  }
  private void lblDragger_MouseMove(System.Object sender,
    System.Windows.Forms.MouseEventArgs e)
  {
    if (isDragging == true)
    {
      lblDragger.Left = e.X + lblDragger.Left - clickOffsetX;
      lblDragger.Top = e.Y + lblDragger.Top - clickOffsetY;
    }
  }
}


Label.Size

  
using System;
using System.Collections.Generic;
using System.ruponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
public class Form1 : Form
{
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.TextBox textBox1;
    private System.Windows.Forms.Button cmdSetText;
    private System.Windows.Forms.Button cmdSetTextConstraint;
  public Form1() {
        InitializeComponent();
  }
    private void InitializeComponent(){
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.label1 = new System.Windows.Forms.Label();
        this.textBox1 = new System.Windows.Forms.TextBox();
        this.cmdSetText = new System.Windows.Forms.Button();
        this.cmdSetTextConstraint = new System.Windows.Forms.Button();
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();
        // 
        // groupBox1
        // 
        this.groupBox1.AutoSize = true;
        this.groupBox1.Controls.Add(this.label1);
        this.groupBox1.Location = new System.Drawing.Point(15, 133);
        this.groupBox1.Margin = new System.Windows.Forms.Padding(20);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(200, 100);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "groupBox1";
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(17, 25);
        this.label1.Margin = new System.Windows.Forms.Padding(5);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(35, 13);
        this.label1.TabIndex = 0;
        this.label1.Text = "label1";
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(15, 12);
        this.textBox1.Multiline = true;
        this.textBox1.Name = "textBox1";
        this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
        this.textBox1.Size = new System.Drawing.Size(200, 47);
        this.textBox1.TabIndex = 1;
        this.textBox1.Text = "The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the l" +
            "azy dog.";
        // 
        // cmdSetText
        // 
        this.cmdSetText.Location = new System.Drawing.Point(50, 65);
        this.cmdSetText.Name = "cmdSetText";
        this.cmdSetText.Size = new System.Drawing.Size(165, 23);
        this.cmdSetText.TabIndex = 2;
        this.cmdSetText.Text = "Set Text";
        this.cmdSetText.UseVisualStyleBackColor = true;
        this.cmdSetText.Click += new System.EventHandler(this.cmdSetText_Click);
        // 
        // cmdSetTextConstraint
        // 
        this.cmdSetTextConstraint.Location = new System.Drawing.Point(50, 91);
        this.cmdSetTextConstraint.Name = "cmdSetTextConstraint";
        this.cmdSetTextConstraint.Size = new System.Drawing.Size(165, 23);
        this.cmdSetTextConstraint.TabIndex = 3;
        this.cmdSetTextConstraint.Text = "Constrain Label and Set Text";
        this.cmdSetTextConstraint.UseVisualStyleBackColor = true;
        this.cmdSetTextConstraint.Click += new System.EventHandler(this.cmdSetTextConstraint_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.AutoSize = true;
        this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this.ClientSize = new System.Drawing.Size(247, 336);
        this.Controls.Add(this.cmdSetTextConstraint);
        this.Controls.Add(this.cmdSetText);
        this.Controls.Add(this.textBox1);
        this.Controls.Add(this.groupBox1);
        this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        this.Name = "Form1";
        this.Text = "Form1";
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();
    }
    private void cmdSetText_Click(object sender, EventArgs e)
    {
        label1.MaximumSize = new Size(0,0);
        label1.Text = "";
        label1.Text = textBox1.Text;
    }
    private void cmdSetTextConstraint_Click(object sender, EventArgs e)
    {
        label1.MaximumSize = new Size(200,0);
        label1.Text = textBox1.Text;
    }
  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }
}


Label.Text

   
using System;
using System.Windows.Forms;
class MainForm : Form
{
    private Label label1;
    private TextBox textBox1;
    private Button button1;
    public MainForm()
    {
         this.label1 = new Label();
         this.textBox1 = new TextBox();
         this.button1 = new Button();
         this.SuspendLayout();
         this.label1.Location = new System.Drawing.Point(16, 36);
         this.label1.Name = "label1";
         this.label1.Size = new System.Drawing.Size(128, 16);
         this.label1.TabIndex = 0;
         this.label1.Text = "Please enter your name:"; 
         this.textBox1.Location = new System.Drawing.Point(152, 32);
         this.textBox1.Name = "textBox1";
         this.textBox1.TabIndex = 1;
         this.textBox1.Text = "";
         this.button1.Location = new System.Drawing.Point(109, 80);
         this.button1.Name = "button1";
         this.button1.TabIndex = 2;
         this.button1.Text = "Enter";
         this.button1.Click += new System.EventHandler(this.button1_Click);
         this.ClientSize = new System.Drawing.Size(292, 126);
         this.Controls.Add(this.button1);
         this.Controls.Add(this.textBox1);
         this.Controls.Add(this.label1);
         this.ResumeLayout(false);
     }
     private void button1_Click(object sender, System.EventArgs e)
     {
        System.Console.WriteLine("User entered: " + textBox1.Text);
        MessageBox.Show("Welcome, " + textBox1.Text, "Visual C#");
     }
     [STAThread]
     public static void Main()
     {
        Application.EnableVisualStyles();
        Application.Run(new MainForm());
     }
}