Resizing and Repositioning Control on a Windows Form at runtime(.Net)

Hi

Is it possible to resize, repositioning controls like (TextBox, Label, ....) during runtime on window Forms in (DotNet). How to proceed with this.

Thanks

Sriram

 




Answer this question

Resizing and Repositioning Control on a Windows Form at runtime(.Net)

  • Deadly Trev

    Thankyou.. Now iam able to move the textbox to another location at runtime, but is it possible to resize it during runtime

    thanks in advance



  • Andy D

    You need to use a Forms designer for your problem.

    http://msdn.microsoft.com/msdnmag/issues/06/03/DesignerHosting/


  • matthewfoster

    private void textBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

    {

    if(e.Button == MouseButtons.Left)

    {

    //Get current X and Y

    int x = e.X;

    int y =e.Y;

    //get deltax and deltay

    textBox1.Left += (x-deltaX);

    textBox1.Top += (y-deltaY);

    }

    }

    private void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)

    {

    deltaX = e.X;

    deltaY = e.Y;

    }


  • plopez

    Do you want to do it something like the VS.net designer

    If not,you can set the Location property and Size property at any point of time.

     


  • Azeem Khan

    You can-

    private void textBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)

    {

    if(e.Button == MouseButtons.Left)

    {

    //Get current X and Y

    int x = e.X;

    int y =e.Y;

    //get deltax and deltay

    textBox1.Left += (x-deltaX);

    textBox1.Top += (y-deltaY);

    textBox1.Height += y-deltaY;

    textBox1.Width += x-deltaX;

    }

    }

    This is some skeleton code,which I hope will get you going!!


  • ploplo

    i will give a scenario, while at run time is it possible to drag a control (TextBox, label...) to another position, and also resize them.

  • Hana

    sorry for delayed reply. Actually resize i was looking is different. i mean it should be like how it behaves in design time. (ie) in design time u will select a textbox and on the rightbottom u will select and resize it, the same behaviour is expected in the runtime also for controls.

  • Resizing and Repositioning Control on a Windows Form at runtime(.Net)