{"id":1600,"date":"2012-11-07T16:56:55","date_gmt":"2012-11-07T14:56:55","guid":{"rendered":"http:\/\/www.hjgode.de\/wp\/?p=1600"},"modified":"2013-01-18T13:36:02","modified_gmt":"2013-01-18T11:36:02","slug":"mobile-development-move-your-form","status":"publish","type":"post","link":"https:\/\/www.hjgode.de\/wp\/2012\/11\/07\/mobile-development-move-your-form\/","title":{"rendered":"Mobile Development: Move your Form"},"content":{"rendered":"<p>Although I do not yet know a use case for this, here comes some code to make your smartdevice forms being moveable.<\/p>\n<p>As default, Windows forms on mobile devices are created always as maximized forms. There may be situations, where you need a moveable form. The trick in compact framework is to use SetWindowLong with WS_CAPTION style and apply that to your form.<\/p>\n<p><a href=\"http:\/\/www.hjgode.de\/wp\/2012\/11\/07\/mobile-development-move-your-form\/move1\/\" rel=\"attachment wp-att-1601\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1601\" title=\"move1\" alt=\"\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move1-225x300.png\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move1-225x300.png 225w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move1-112x150.png 112w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move1.png 240w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a>\u00a0\u00a0 <a href=\"http:\/\/www.hjgode.de\/wp\/2012\/11\/07\/mobile-development-move-your-form\/move2\/\" rel=\"attachment wp-att-1602\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1602\" title=\"move2\" alt=\"\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move2-225x300.png\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move2-225x300.png 225w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move2-112x150.png 112w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/move2.png 240w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>To enable you to experminet more with Window Styles there is another demo enabling to check all known window stlyes with a form. Be warned, setting WS_DISABLED or some other styles will make your form inaccessible.<\/p>\n<p><!--more--><\/p>\n<p><a href=\"http:\/\/www.hjgode.de\/wp\/2012\/11\/07\/mobile-development-move-your-form\/win_styles\/\" rel=\"attachment wp-att-1604\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1604\" title=\"win_styles\" alt=\"\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_styles-225x300.png\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_styles-225x300.png 225w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_styles-112x150.png 112w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_styles.png 240w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a>\u00a0\u00a0 <a href=\"http:\/\/www.hjgode.de\/wp\/2012\/11\/07\/mobile-development-move-your-form\/win_exstyles\/\" rel=\"attachment wp-att-1603\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-1603\" title=\"win_exstyles\" alt=\"\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_exstyles-225x300.png\" width=\"225\" height=\"300\" srcset=\"https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_exstyles-225x300.png 225w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_exstyles-112x150.png 112w, https:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/win_exstyles.png 240w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/a><\/p>\n<p>The above changes or Window Styles are well known to every native C Windows programmer. Possibly you are now curious what else can be done with a good background knowledge of Windows API programming.<\/p>\n<p>Another nice piece of code is how to get a list of an enum type. The below needs a list of options to build the checkboxes in the form:<\/p>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/build a list of chk options for WSYTLES\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 void buildOptions()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 string[] stylesList = winapi.getStyles();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int iCount=0;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 foreach (string s in stylesList)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 CheckBox chkBox = new CheckBox();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 chkBox.Left = offsetX;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 chkBox.Top = iCount * offsetY;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 chkBox.Size = new Size(widthX, heightX);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 chkBox.Text = s;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 uint uStyle = (uint)Enum.Parse(typeof(winapi.WINSTYLES),s,false);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if ((uiCurrentStyle &amp; uStyle) == uStyle)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 chkBox.Checked = true;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 chkBox.CheckStateChanged += new EventHandler(chkBox_CheckStateChanged);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 tabPage1.Controls.Add(chkBox);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 iCount++;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<p>But an enum can not be enumerated ( great wording \ud83d\ude42 ). Although you could build the list by hand, I am a lazy programmer. I already have entered all the values as an enum. But there is a solution:<\/p>\n<pre>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static string[] getStyles()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List&lt;string&gt; list = new List&lt;string&gt;();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 foreach (WINSTYLES ws in GetValues(new WINSTYLES()))\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 list.Add(ws.ToString());\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return list.ToArray();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<p>with the special GetValues() function for the enum (WINSTYLES):<\/p>\n<pre>        ...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [Flags]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public enum WINSTYLES:uint{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WS_OVERLAPPED =\u00a0\u00a0\u00a0\u00a0 0x00000000,\u00a0\u00a0\u00a0 \/\/#define WS_OVERLAPPED\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WS_BORDER | WS_CAPTION\r\n...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WS_MAXIMIZE=\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0x01000000,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WS_CAPTION =\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0x00C00000,\u00a0\u00a0\u00a0 \/\/#define WS_CAPTION\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 0x00C00000L\u00a0\u00a0\u00a0\u00a0 \/* WS_BORDER | WS_DLGFRAME\u00a0 *\/\r\n\u00a0...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WS_MAXIMIZEBOX=\u00a0\u00a0\u00a0\u00a0 0x00010000,\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 WS_POPUPWINDOW=\u00a0\u00a0\u00a0\u00a0 0x80880000,\u00a0\u00a0\u00a0\u00a0 \/\/ \u00a0\u00a0 \u00a0Creates a pop-up window with WS_BORDER, WS_POPUP, and WS_SYSMENU styles. The WS_CAPTION and WS_POPUPWINDOW styles must be combined to make the window menu visible.\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }        \r\n...\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/great stuff by http:\/\/ideas.dalezak.ca\/2008\/11\/enumgetvalues-in-compact-framework.html\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 public static IEnumerable&lt;Enum&gt; GetValues(Enum enumeration)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 List&lt;Enum&gt; enumerations = new List&lt;Enum&gt;();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 foreach (FieldInfo fieldInfo in enumeration.GetType().GetFields(\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 BindingFlags.Static | BindingFlags.Public))\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 enumerations.Add((Enum)fieldInfo.GetValue(enumeration));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 return enumerations;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<\/pre>\n<p>Have fun.<\/p>\n[Download not found]\n<p>Source code at <a href=\"http:\/\/code.google.com\/p\/win-mobile-code\/source\/browse\/#svn%2Ftrunk%2FMoveableWinForm%2FMovableForm\" target=\"_blank\">code.google.com<\/a><\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Update 18. jan 2013:<\/strong><\/span><br \/>\nadded class to enable you to subclass a form and get ALL window messages. Here an example of a WM_MOVE:<\/p>\n<p><a href=\"http:\/\/www.hjgode.de\/wp\/2012\/11\/07\/mobile-development-move-your-form\/moveableform_wm_move\/\" rel=\"attachment wp-att-1679\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1679\" alt=\"MoveableForm_WM_MOVE\" src=\"http:\/\/www.hjgode.de\/wp\/wp-content\/uploads\/2012\/11\/MoveableForm_WM_MOVE.gif\" width=\"240\" height=\"320\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Although I do not yet know a use case for this, here comes some code to make your smartdevice forms being moveable. As default, Windows forms on mobile devices are created always as maximized forms. There may be situations, where you need a moveable form. The trick in compact framework is to use SetWindowLong with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[178,3,4],"tags":[120,169,471,318,15],"class_list":["post-1600","post","type-post","status-publish","format-standard","hentry","category-codeproject","category-programming","category-tools","tag-api","tag-compact-framework","tag-form","tag-subclass","tag-windows-mobile"],"_links":{"self":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts\/1600"}],"collection":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/comments?post=1600"}],"version-history":[{"count":5,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts\/1600\/revisions"}],"predecessor-version":[{"id":1618,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/posts\/1600\/revisions\/1618"}],"wp:attachment":[{"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/media?parent=1600"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/categories?post=1600"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hjgode.de\/wp\/wp-json\/wp\/v2\/tags?post=1600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}