{"id":3320,"date":"2014-03-22T02:36:08","date_gmt":"2014-03-22T02:36:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/22\/move-dynamic-contorls-during-runtime-within-the-panel-or-some-container-like-panel-collection-of-common-programming-errors\/"},"modified":"2014-03-22T02:36:08","modified_gmt":"2014-03-22T02:36:08","slug":"move-dynamic-contorls-during-runtime-within-the-panel-or-some-container-like-panel-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/22\/move-dynamic-contorls-during-runtime-within-the-panel-or-some-container-like-panel-collection-of-common-programming-errors\/","title":{"rendered":"move dynamic Contorls during runtime within the panel or some container like panel-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 I was trying to move some dynamic control within the parent container like panel or a group box how do i do that?any help<\/li>\n<li>\n<h3>13 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<table>\n<tr>\n<td>Private\u00a0dragging\u00a0As\u00a0Boolean\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0Private\u00a0beginX,\u00a0beginY\u00a0As\u00a0Integer\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0Public\u00a0Sub\u00a0Hand_CustomDown(ByVal\u00a0sender\u00a0As\u00a0Object,\u00a0ByVal\u00a0e\u00a0As\u00a0\u00a0_\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.Windows.Forms.MouseEventArgs)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dragging\u00a0=\u00a0True\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0beginX\u00a0=\u00a0e.X\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0beginY\u00a0=\u00a0e.Y\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0Public\u00a0Sub\u00a0Hand_CustomMove(ByVal\u00a0sender\u00a0As\u00a0Object,\u00a0ByVal\u00a0e\u00a0As\u00a0\u00a0_\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0System.Windows.Forms.MouseEventArgs)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If\u00a0dragging\u00a0=\u00a0True\u00a0Then\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If\u00a0e.X\u00a0&gt;\u00a00\u00a0And\u00a0e.Y\u00a0&gt;\u00a00\u00a0Then\u00a0<\/td>\n<\/tr>\n<tr>\n<td>&#8216; the code for checking the parent container goes here<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sender.Location\u00a0=\u00a0New\u00a0Point(sender.Location.X\u00a0+\u00a0e.X\u00a0&#8211;\u00a0beginX,\u00a0_\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sender.Location.Y\u00a0+\u00a0e.Y\u00a0&#8211;\u00a0beginY)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Me.Refresh()\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0End\u00a0If\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0End\u00a0If\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0Public\u00a0Sub\u00a0Hand_CustomUp(ByVal\u00a0sender\u00a0As\u00a0Object,\u00a0ByVal\u00a0e\u00a0As\u00a0\u00a0_\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0System.Windows.Forms.MouseEventArgs)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dragging\u00a0=\u00a0False\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<\/table>\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>any controls made on runtime<\/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>Add handlers for the MouseDown\u00a0and MouseMove events and move than as design time controls.<\/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>the move is the part im looking for and trying to control the move within a container<\/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<table>\n<tr>\n<td>Private\u00a0Sub\u00a0Form1_Load()\u00a0Handles\u00a0Me.Load\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Dim\u00a0T\u00a0as\u00a0New\u00a0Panel\u00a0<\/td>\n<\/tr>\n<tr>\n<td>T.backColor\u00a0=\u00a0Color.Black\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Me.Controls.Add(T)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Addhandler\u00a0T.MouseDown,\u00a0Addressof\u00a0Hand_CustomDown\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Addhandler\u00a0T.MouseMove,\u00a0Addressof\u00a0Hand_CustomMove\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Addhandler\u00a0T.MouseUP,\u00a0Addressof\u00a0Hand_CustomUp\u00a0<\/td>\n<\/tr>\n<tr>\n<td>End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Dim\u00a0ShouldIMove\u00a0as\u00a0Boolean\u00a0=\u00a0False\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Private\u00a0Sub\u00a0Hand_CustomDown\u00a0<\/td>\n<\/tr>\n<tr>\n<td>ShouldIMove\u00a0=\u00a0True\u00a0<\/td>\n<\/tr>\n<tr>\n<td>End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Private\u00a0Sub\u00a0Hand_CustomMove(ByVal\u00a0Sender\u00a0as\u00a0System.Object,\u00a0ByVal\u00a0E\u00a0as\u00a0System.EventArgs)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>If\u00a0ShouldIMove\u00a0=\u00a0True\u00a0Then\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Sender.Location\u00a0=\u00a0Me.PointToClient(Cursor.Position)\u00a0<\/td>\n<\/tr>\n<tr>\n<td>End\u00a0If\u00a0<\/td>\n<\/tr>\n<tr>\n<td>End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>Private\u00a0Sub\u00a0Hand_CustomUp\u00a0<\/td>\n<\/tr>\n<tr>\n<td>ShouldIMove\u00a0=\u00a0False\u00a0<\/td>\n<\/tr>\n<tr>\n<td>End\u00a0Sub\u00a0<\/td>\n<\/tr>\n<\/table>\n<p><\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn6 here is my scenarioi\u00a0 have like panels and each panels have few controls that are created on runtimei would like to move the contorls inside the panel , but cannot be move outside of the panels.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.msdn.microsoft.com\/dn186180.LOGO_Win1211(id-id,MSDN.10).png\" \/><br \/>\nmsdn7 then just check the location and make sure it is inside the panel:<\/p>\n<table>\n<tr>\n<td>Private\u00a0Sub\u00a0Hand_CustomMove(ByVal\u00a0Sender\u00a0as\u00a0System.Object,\u00a0ByVal\u00a0E\u00a0as\u00a0System.EventArgs)\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>&#8216;Check\u00a0if\u00a0the\u00a0Mouse\u00a0is\u00a0Down\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>If\u00a0ShouldIMove\u00a0=\u00a0True\u00a0Then\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0Dim\u00a0MousePT\u00a0as\u00a0Point\u00a0=\u00a0Me.PointToClient(Cursor.Position)\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0&#8216;Check\u00a0if\u00a0the\u00a0Mouse\u00a0Location\u00a0is\u00a0Greater\u00a0than\u00a0the\u00a0Upper\u00a0Left\u00a0Point&#8217;s\u00a0X\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0&#8216;Check\u00a0if\u00a0the\u00a0Mouse\u00a0Location\u00a0is\u00a0Less\u00a0than\u00a0the\u00a0Upper\u00a0Left\u00a0Point&#8217;s\u00a0Y\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0If\u00a0(MousePT.X\u00a0&gt;\u00a0Panel1.Location.X)\u00a0And\u00a0(MousePT.Y\u00a0\u00a0Me.PointToClient(ctrl.Parent.Location).X)\u00a0And\u00a0(MousePT.Y\u00a0&gt;\u00a0Me.PointToClient(ctrl.Parent.Location).Y)\u00a0Then\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;Check\u00a0if\u00a0the\u00a0Mouse\u00a0Location\u00a0is\u00a0Less\u00a0than\u00a0the\u00a0Lower\u00a0Right\u00a0Point&#8217;s\u00a0X\u00a0+\u00a010px\u00a0Buffer\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0&#8216;Check\u00a0if\u00a0the\u00a0Mouse\u00a0Location\u00a0is\u00a0Greater\u00a0than\u00a0the\u00a0Lower\u00a0Right\u00a0Point&#8217;s\u00a0Y\u00a0+\u00a010px\u00a0Buffer\u00a0\u00a0\u00a0<\/td>\n<\/tr>\n<tr>\n<td>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If\u00a0(MousePT.X\u00a0<\/td>\n<\/tr>\n<\/table>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>msdn I was trying to move some dynamic control within the parent container like panel or a group box how do i do that?any help 13 Answers msdn1 Private\u00a0dragging\u00a0As\u00a0Boolean\u00a0 \u00a0\u00a0\u00a0\u00a0Private\u00a0beginX,\u00a0beginY\u00a0As\u00a0Integer\u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0Public\u00a0Sub\u00a0Hand_CustomDown(ByVal\u00a0sender\u00a0As\u00a0Object,\u00a0ByVal\u00a0e\u00a0As\u00a0\u00a0_\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0System.Windows.Forms.MouseEventArgs)\u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0dragging\u00a0=\u00a0True\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0beginX\u00a0=\u00a0e.X\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0beginY\u00a0=\u00a0e.Y\u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0End\u00a0Sub\u00a0 \u00a0 \u00a0\u00a0\u00a0\u00a0Public\u00a0Sub\u00a0Hand_CustomMove(ByVal\u00a0sender\u00a0As\u00a0Object,\u00a0ByVal\u00a0e\u00a0As\u00a0\u00a0_\u00a0 \u00a0\u00a0\u00a0\u00a0System.Windows.Forms.MouseEventArgs)\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If\u00a0dragging\u00a0=\u00a0True\u00a0Then\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0If\u00a0e.X\u00a0&gt;\u00a00\u00a0And\u00a0e.Y\u00a0&gt;\u00a00\u00a0Then\u00a0 &#8216; the code for checking the parent container goes here \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0sender.Location\u00a0=\u00a0New\u00a0Point(sender.Location.X\u00a0+\u00a0e.X\u00a0&#8211;\u00a0beginX,\u00a0_\u00a0 [&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-3320","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3320","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=3320"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3320\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}