Label auto resize : Label « GUI Windows Form « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » GUI Windows Form » LabelScreenshots 
Label auto resize
Label auto resize


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.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(15133);
        this.groupBox1.Margin = new System.Windows.Forms.Padding(20);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(200100);
        this.groupBox1.TabIndex = 0;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "groupBox1";
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(1725);
        this.label1.Margin = new System.Windows.Forms.Padding(5);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(3513);
        this.label1.TabIndex = 0;
        this.label1.Text = "label1";
        // 
        // textBox1
        // 
        this.textBox1.Location = new System.Drawing.Point(1512);
        this.textBox1.Multiline = true;
        this.textBox1.Name = "textBox1";
        this.textBox1.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
        this.textBox1.Size = new System.Drawing.Size(20047);
        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(5065);
        this.cmdSetText.Name = "cmdSetText";
        this.cmdSetText.Size = new System.Drawing.Size(16523);
        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(5091);
        this.cmdSetTextConstraint.Name = "cmdSetTextConstraint";
        this.cmdSetTextConstraint.Size = new System.Drawing.Size(16523);
        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(6F13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.AutoSize = true;
        this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
        this.ClientSize = new System.Drawing.Size(247336);
        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());
  }

}


           
       
Related examples in the same category
1.Label: Localtion, Name, Size, TabIndex, Text
2.Add image to Label and set ImageAlign to MiddleRightAdd image to Label and set ImageAlign to MiddleRight
3.Label grows as the inner textLabel grows as the inner text
4.Set Label Background, foreground color and border styleSet Label Background, foreground color and border style
5.Marquee Label HostMarquee Label Host
6.Use Label and Timer to create a Clock
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.