Windows Develop Bookmark and Share   
 index > Windows Forms General > Resizing and Repositioning Control on a Windows Form at runtime(.Net)
 

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

 

S.Sriram  Thursday, May 11, 2006 8:57 AM

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;

}

Karthik Krishnaswami  Thursday, May 11, 2006 10:42 AM

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.

 

Karthik Krishnaswami  Thursday, May 11, 2006 9:44 AM
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.
S.Sriram  Thursday, May 11, 2006 10:06 AM

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;

}

Karthik Krishnaswami  Thursday, May 11, 2006 10:42 AM

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

S.Sriram  Thursday, May 11, 2006 11:09 AM

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!!

Karthik Krishnaswami  Thursday, May 11, 2006 11:38 AM
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.
S.Sriram  Monday, May 15, 2006 5:38 AM

You need to use a Forms designer for your problem.

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

Karthik Krishnaswami  Monday, May 15, 2006 9:30 AM

You can use google to search for other answers

Custom Search

More Threads

• FolderBrowserDialog empty
• How to: Webbrowser NewWindow and Navigating equivalent to axWebbrowser
• Where can I find the REAL cool buttons, tab's and other graphics
• Progerss bar
• How can I get the Datetimepicker's selected part
• The object is currently in use elsewhere.
• How get Bitmap From MemoryStream
• help PictureBox, showWindow()
• Any consultants out there know what 'Normal' terms are to a client?
• Application.ThreadException looses some exception information