{"id":34,"date":"2008-12-20T00:13:00","date_gmt":"2008-12-19T18:43:00","guid":{"rendered":"http:\/\/www.smallguru.com\/?p=33"},"modified":"2008-12-20T00:13:00","modified_gmt":"2008-12-19T18:43:00","slug":"minimize-forms-along-with-parent-application-or-form-in-csharp","status":"publish","type":"post","link":"https:\/\/www.ar-cad.com\/smallguru\/2008\/12\/minimize-forms-along-with-parent-application-or-form-in-csharp\/","title":{"rendered":"Minimize forms along with Parent Application or Form in C#"},"content":{"rendered":"<p>How to minimize forms that belong to a particular application, when the parent application (In my case Autodesk Inventor) is minimized ? When you create software or addins, you would want the forms\/dialogs to be minimized and not floating around when parent application is minimized.<\/p>\n<p>For that we need to deal with hWnd of parent application. &#8220;hWnd&#8221; stands for Window Handle, which is the API call to the window(parent application). Since we come across this too often in Inventor customization to make addins, I have created a Class and a couple of methods for better clarity. Before I go into details, lets see what are the different types of Forms\/Dialogs you would deal while developing Windows based software.<\/p>\n<div style=\"clear:both;\"><strong>1)Modal Forms or Dialog Box<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft\" style=\"float: left;\" src=\"http:\/\/smallguru.com\/wordpress\/wp-content\/upload\/modalIN-Motion.png\" alt=\"Modal Form\" \/><\/p>\n<p>The modal forms are used when you want the user to enter some values and unless the form\/dialog is closed, he\/she cannot interact with other controls in the application. All the MessageBox&#8217;s are of modal types. The image on the left is also an example of Modal forms. Here, the user has to enter\/select details of Graph plots in our addin IN-Motion.<\/p>\n<\/div>\n<div style=\"clear:both;\">\n<hr style=\"display:block\" \/><strong>2. Modeless Form<\/strong><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignleft\" style=\"float: left;\" src=\"http:\/\/smallguru.com\/wordpress\/wp-content\/upload\/modelessIN-Motion.png\" alt=\"\" \/><\/p>\n<p>The modeless forms are used when user can enter values into the form and also can interact with other controls in application, even when the form is not minimized. The image on the left is the Simulation playback deck in IN-Motion.<\/p>\n<\/div>\n<div style=\"clear:both;\">\n<hr style=\"display:block\" \/>Coming back to our problem of minimizing forms with parent application, below is the code. If the user minimizes Inventor application(parent form), its child forms are also minimized.<br \/>\n[sourcecode language=&#8217;c#&#8217;]<br \/>\n\/\/<br \/>\n\/\/Declare and set..here m_inventorApplication is the application<br \/>\n\/\/MainFrameHWND returns its handle.<br \/>\n\/\/WindowsWrapperForForm is a Class, defined at the bottom<br \/>\nWindowsWrapperForForm m_windowsWrapperForForm = new<br \/>\nWindowsWrapperForForm((IntPtr)m_inventorApplication.MainFrameHWND);<\/p>\n<p>\/\/Declare and set a form .. ModalCmdDlg is our modal form<br \/>\nModalCmdDlg m_modalCmdDlg = new ModalCmdDlg();<\/p>\n<p>\/\/Declare and set a form .. ModelessCmdDlg is our modeless form<br \/>\nModelessCmdDlg m_modelessCmdDlg = new ModelessCmdDlg();<\/p>\n<p>\/\/Show Modal form<br \/>\nShowModalForm(m_modalCmdDlg);<\/p>\n<p>\/\/Show Modeless form<br \/>\nShowModelessForm(m_modelessCmdDlg);<\/p>\n<p>\/\/Methods<br \/>\nprivate void ShowModalForm(Form _modalCmdDlg)<br \/>\n{<br \/>\n_modalCmdDlg.Activate();<br \/>\n_modalCmdDlg.ShowInTaskbar = false;<br \/>\n\/\/ShowDialog is used..for Modal forms<br \/>\n_modalCmdDlg.ShowDialog(m_windowsWrapperForForm);<br \/>\n}<\/p>\n<p>private void ShowModelessForm(Form _modelessCmdDlg)<br \/>\n{<br \/>\n_modelessCmdDlg.Activate();<br \/>\n_modelessCmdDlg.ShowInTaskbar = false;<br \/>\n\/\/Show is used..for Modeless forms<br \/>\n_modelessCmdDlg.Show(m_windowsWrapperForForm);<br \/>\n}<\/p>\n<p>\/\/Below is the code for Class WindowsWrapperForForm<br \/>\n\/\/****************Class***************<\/p>\n<p>class WindowsWrapperForForm : System.Windows.Forms.IWin32Window<\/p>\n<p>{<br \/>\nprivate IntPtr m_hwnd;<br \/>\npublic WindowsWrapperForForm(IntPtr handle)<br \/>\n{<br \/>\nm_hwnd = handle;<br \/>\n}<br \/>\n#region IWin32Window Members<br \/>\npublic IntPtr Handle<br \/>\n{<br \/>\nget { return m_hwnd; }<br \/>\n}<br \/>\n#endregion<br \/>\n}<br \/>\n\/\/****************EndClass*******************<\/p>\n<p>[\/sourcecode]<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>How to minimize forms that belong to a particular application, when the parent application (In my case Autodesk Inventor) is minimized ? When you create software or addins, you would want the forms\/dialogs to be minimized and not floating around &hellip; <a href=\"https:\/\/www.ar-cad.com\/smallguru\/2008\/12\/minimize-forms-along-with-parent-application-or-form-in-csharp\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":62,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[2,5,7,8],"tags":[35,37,29],"class_list":["post-34","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-cad","category-inventor-customization","category-tutorials","category-visual-c","tag-inventor-customization","tag-visual-c","tag-visual-studio"],"_links":{"self":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/posts\/34","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/comments?post=34"}],"version-history":[{"count":0,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/posts\/34\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/media?parent=34"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/categories?post=34"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ar-cad.com\/smallguru\/wp-json\/wp\/v2\/tags?post=34"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}