Set Label Border style to FixedSingle

image_pdfimage_print


   

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
   private System.Windows.Forms.Label firstLabel;
   private System.Windows.Forms.Label secondLabel;
   private System.Windows.Forms.ToolTip labelsToolTip;

   public Form1() {
       InitializeComponent();
   }

   private void InitializeComponent()
   {
      this.firstLabel = new System.Windows.Forms.Label();
      this.secondLabel = new System.Windows.Forms.Label();
      this.labelsToolTip = new System.Windows.Forms.ToolTip(new System.ComponentModel.Container());
      this.SuspendLayout();
      // 
      // firstLabel
      // 
      this.firstLabel.AutoSize = true;
      this.firstLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
      this.firstLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.firstLabel.Location = new System.Drawing.Point(12, 20);
      this.firstLabel.Name = "firstLabel";
      this.firstLabel.Size = new System.Drawing.Size(92, 18);
      this.firstLabel.TabIndex = 0;
      this.firstLabel.Text = "This is a label.";
      this.labelsToolTip.SetToolTip(this.firstLabel, "First Label");
      // 
      // secondLabel
      // 
      this.secondLabel.AutoSize = true;
      this.secondLabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
      this.secondLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.secondLabel.Location = new System.Drawing.Point(12, 69);
      this.secondLabel.Name = "secondLabel";
      this.secondLabel.Size = new System.Drawing.Size(133, 18);
      this.secondLabel.TabIndex = 1;
      this.secondLabel.Tag = "";
      this.secondLabel.Text = "This is another Label.";
      this.labelsToolTip.SetToolTip(this.secondLabel, "Second Label");
      // 
      // ToolTipExampleForm
      // 
      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
      this.ClientSize = new System.Drawing.Size(252, 124);
      this.Controls.Add(this.secondLabel);
      this.Controls.Add(this.firstLabel);
      this.Name = "ToolTipExampleForm";
      this.Text = "ToolTip Demonstration";
      this.ResumeLayout(false);
      this.PerformLayout();

   }

  [STAThread]
  static void Main()
  {
    Application.EnableVisualStyles();
    Application.Run(new Form1());
  }

}



           
          


Button Image, Size, Parent

image_pdfimage_print
   
 



using System;
using System.Drawing;
using System.Windows.Forms;
   
class BitmapButtons: Form
{
     int    cxBtn, cyBtn, dxBtn;
     Button btnLarger, btnSmaller;
   
     public static void Main()
     {
          Application.Run(new BitmapButtons());
     }
     public BitmapButtons()
     {
          ResizeRedraw = true;
   
          dxBtn = Font.Height;
          btnLarger = new Button();
          btnLarger.Parent = this;
          btnLarger.Image  = new Bitmap(GetType(), "LargerButton.bmp") ;
   
          cxBtn = btnLarger.Image.Width  + 8;
          cyBtn = btnLarger.Image.Height + 8;
   
          btnLarger.Size   = new Size(cxBtn, cyBtn);
          btnLarger.Click += new EventHandler(ButtonLargerOnClick);
   
          btnSmaller = new Button();
          btnSmaller.Parent = this;
          btnSmaller.Image  = new Bitmap(GetType(), "SmallerButton.bmp");
          btnSmaller.Size   = new Size(cxBtn, cyBtn);
          btnSmaller.Click += new EventHandler(ButtonSmallerOnClick);
   
          OnResize(EventArgs.Empty);
     }
     protected override void OnResize(EventArgs ea)
     {
          base.OnResize(ea);
   
          btnLarger.Location = new Point(ClientSize.Width / 2 - cxBtn - dxBtn / 2,
                                  (ClientSize.Height - cyBtn) / 2);
          btnSmaller.Location = new Point(ClientSize.Width / 2 + dxBtn / 2,
                                  (ClientSize.Height - cyBtn) / 2);
     }
     void ButtonLargerOnClick(object obj, EventArgs ea)
     {
          Left   = 50;
          Top    = 50;
          Width  = 50;
          Height = 50;
     }
     void ButtonSmallerOnClick(object obj, EventArgs ea)
     {
          Left   = 200;
          Top    = 200;
          Width  = 20;
          Height = 20;
     }
}

    


Button Name, TabIndex, Text

image_pdfimage_print
   
 

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());
     }
}

    


Anchor Style: Right

image_pdfimage_print


   

  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  public class AnchorForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Button button1;

    public AnchorForm()
    {
      InitializeComponent();
      CenterToScreen();
    }
    private void InitializeComponent()
    {
      this.button1 = new System.Windows.Forms.Button();
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1});
      this.Text = "Anchoring (and Docking) Controls";
      
            // anchor Right
        
      button1.Anchor = AnchorStyles.Right;
      button1.Text = "Anchor: " + button1.Anchor.ToString() + 
        "
Dock: " + button1.Dock.ToString();
    }
    static void Main() 
    {
      Application.Run(new AnchorForm());
    }

  }


           
          


Anchor Style: Bottom

image_pdfimage_print


   

  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  public class AnchorForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Button button1;

    public AnchorForm()
    {
      InitializeComponent();
      CenterToScreen();
    }
    private void InitializeComponent()
    {
      this.button1 = new System.Windows.Forms.Button();
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1});
      this.Text = "Anchoring (and Docking) Controls";
      
            // anchor Bottom
            
      button1.Anchor = AnchorStyles.Bottom;
      button1.Dock = DockStyle.Left;
      button1.Text = "Anchor: " + button1.Anchor.ToString() + 
        "
Dock: " + button1.Dock.ToString();

    }
    static void Main() 
    {
      Application.Run(new AnchorForm());
    }

  }


           
          


Anchor Left and Top

image_pdfimage_print


   


  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  public class AnchorForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.Button button1;

    public AnchorForm()
    {
      InitializeComponent();
      CenterToScreen();
    }
    private void InitializeComponent()
    {
      this.button1 = new System.Windows.Forms.Button();
      this.Controls.AddRange(new System.Windows.Forms.Control[] {this.button1});
      this.Text = "Anchoring (and Docking) Controls";
      
            // anchor left and top
            button1.Anchor = AnchorStyles.Top | AnchorStyles.Left;
      button1.Text = "Anchor: " + button1.Anchor.ToString() + 
        "
Dock: " + button1.Dock.ToString();



    }
    static void Main() 
    {
      Application.Run(new AnchorForm());
    }

  }