Resizing and Repositioning Control on a Windows Form at runtime(.Net)-Collection of common programming errors
msdnHi
Is it possible to resize, repositioning controls like (TextBox, Label, ….) during runtime on window Forms in (DotNet). How to proceed with this.
Thanks
Sriram
-
8 Answers
msdn1private
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;
}
msdn2i will give a scenario, while at run time is it possible to drag a control (TextBox, label…) to another position, and also resize them.
msdn3private
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;
}
msdn4Thankyou.. Now iam able to move the textbox to another location at runtime, but is it possible to resize it during runtime
thanks in advance
msdn5You 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!!
msdn6sorry 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.
msdn7
msdn8 hi, with use ControlMoverOrResizer class in http://www.codeproject.com/Tips/709121/Move-and-resize-controls-on-a-form-at-runtime-with you can do movable and resizable control in run time just with a line of code! 🙂example:
ControlMoverOrResizer.Init(button1);
and now button1 is a movable and resizable control!