Abhijeet Ghatage
Abhijeet Ghatage

Reputation: 29

Change the width of label when form get resized

I want to change the width of the label as user resize the form.

This is the code that I tried:

    public partial class Form1 : Form
    {
        int lb;

        public Form1()
        {
            InitializeComponent();
            lb = this.Width - label1.Width;
        }

        private void Form1_Resize(object sender, EventArgs e)
        {
            label1.Width = lbl() ;
        }

        private int lbl()
        {
            return this.Width / 2 - lb;
        }
   }

Upvotes: 2

Views: 182

Answers (1)

Denis Voituron
Denis Voituron

Reputation: 298

Use the Anchor property to link your label with form borders.

UPDATE: You can also use TableLayoutPanel to dynamically lays out its contents: http://bit.ly/1KWypIX

Upvotes: 1

Related Questions