{"id":3383,"date":"2014-03-23T13:50:29","date_gmt":"2014-03-23T13:50:29","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/resizing-and-repositioning-control-on-a-windows-form-at-runtime-net-collection-of-common-programming-errors-2\/"},"modified":"2014-03-23T13:50:29","modified_gmt":"2014-03-23T13:50:29","slug":"resizing-and-repositioning-control-on-a-windows-form-at-runtime-net-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/23\/resizing-and-repositioning-control-on-a-windows-form-at-runtime-net-collection-of-common-programming-errors-2\/","title":{"rendered":"Resizing and Repositioning Control on a Windows Form at runtime(.Net)-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn<\/p>\n<p>Hi<\/p>\n<p>Is it possible to resize, repositioning\u00a0controls like (TextBox, Label, &#8230;.) during runtime on window Forms in (DotNet). How to proceed with this.<\/p>\n<p>Thanks<\/p>\n<p>Sriram<\/p>\n<\/li>\n<li>\n<h3>8 Answers<\/h3>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn1<\/p>\n<p>private<\/p>\n<p>void textBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<\/p>\n<p>{<\/p>\n<p>if(e.Button == MouseButtons.Left)<\/p>\n<p>{<\/p>\n<p>\/\/Get current X and Y int x = e.X;int y =e.Y;\/\/get deltax and deltay<\/p>\n<p>textBox1.Left += (x-deltaX);<\/p>\n<p>textBox1.Top += (y-deltaY);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>private void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<\/p>\n<p>{<\/p>\n<p>deltaX = e.X;<\/p>\n<p>deltaY = e.Y;<\/p>\n<p>}<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn2<\/p>\n<p>i will give a scenario, while at run time is it possible to drag a control (TextBox, label&#8230;) to another position, and also resize them.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn3<\/p>\n<p>private<\/p>\n<p>void textBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<\/p>\n<p>{<\/p>\n<p>if(e.Button == MouseButtons.Left)<\/p>\n<p>{<\/p>\n<p>\/\/Get current X and Y int x = e.X;int y =e.Y;\/\/get deltax and deltay<\/p>\n<p>textBox1.Left += (x-deltaX);<\/p>\n<p>textBox1.Top += (y-deltaY);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>private void textBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)<\/p>\n<p>{<\/p>\n<p>deltaX = e.X;<\/p>\n<p>deltaY = e.Y;<\/p>\n<p>}<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn4<\/p>\n<p>Thankyou.. Now iam able to move the textbox to another location at runtime, but is it possible to resize it during runtime<\/p>\n<p>thanks in advance<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn5<\/p>\n<p>You can-<\/p>\n<p>private<\/p>\n<p>void textBox1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)<\/p>\n<p>{<\/p>\n<p>if(e.Button == MouseButtons.Left)<\/p>\n<p>{<\/p>\n<p>\/\/Get current X and Y int x = e.X;int y =e.Y;\/\/get deltax and deltay<\/p>\n<p>textBox1.Left += (x-deltaX);<\/p>\n<p>textBox1.Top += (y-deltaY);<\/p>\n<p>textBox1.Height += y-deltaY;<\/p>\n<p>textBox1.Width += x-deltaX;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>This is some skeleton code,which I hope will get you going!!<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn6<\/p>\n<p>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.<\/p>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn7<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn8 \u00a0 hi, with use <strong>ControlMoverOrResizer<\/strong> 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! \ud83d\ude42<\/p>\n<p>example:<\/p>\n<pre>    ControlMoverOrResizer.Init(button1);   <\/pre>\n<p>and now <em>button1<\/em> is a movable and resizable control!<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn Hi Is it possible to resize, repositioning\u00a0controls like (TextBox, Label, &#8230;.) during runtime on window Forms in (DotNet). How to proceed with this. Thanks Sriram 8 Answers msdn1 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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3383","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3383","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3383"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3383\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3383"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}