{"id":172,"date":"2010-03-30T21:07:27","date_gmt":"2010-03-30T21:07:27","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=172"},"modified":"2022-02-17T06:24:05","modified_gmt":"2022-02-17T06:24:05","slug":"general-form-usage","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/forms\/general-form-usage","title":{"rendered":".General Form Usage"},"content":{"rendered":"<h4>\nOpening a form<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n#include &quot;FormName.h&quot;\t\t\t\/\/Add this at top of file\r\n\r\n\tfrmConfiguration ^ConfigForm = gcnew frmConfiguration();\r\n\tConfigForm-&gt;PassedValue1 = &quot;This is a string I&#39;m passing&quot;;\r\n\r\n\t\/\/TO OPEN AS A DIALOG FORM:\r\n\tConfigForm-&gt;ShowDialog();\r\n\t\/\/or\r\n\tif (ConfigForm-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK)\r\n\telse if (ConfigForm-&gt;DialogResult == System::Windows::Forms::DialogResult::Cancel)\r\n\r\n\t\/\/TO OPEN NOT AS A DIALOG FORM:\r\n\tConfigForm-&gt;Show();\r\n<\/code><\/pre>\n<h4>\nClosing a form<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\tClose();\r\n\t\/\/or\r\n\tthis-&gt;Close();\r\n<\/code><\/pre>\n<h4>\nClosing a form from the Form Load Event<br \/>\n<\/h4>\n<p>\nYou can&#39;t use this-&gt;Close as the form has not yet finished loading so if you do you&#39;ll cause fatal error. Instead use this:\n<\/p>\n<pre>\r\n<code>\r\n\tthis-&gt;BeginInvoke(gcnew MethodInvoker(this, &amp;System::Windows::Forms::Form::Close));\r\n<\/code><\/pre>\n<h4>\nDynamically updating Form Properties<br \/>\n<\/h4>\n<p>\nUse this instead of the forms name:\n<\/p>\n<pre>\r\n<code>\tthis-&gt;Text = &quot;A New Title For This Form&quot;;<\/code><\/pre>\n<h4>\nTo Disable A Form<br \/>\n<\/h4>\n<pre>\r\n<code>\r\n\t\/\/This form\r\n\tthis-&gt;Enabled = false;\r\n\t\/\/Another form\r\n\tfrmMyForm-&gt;Enabled = false;\r\n<\/code><\/pre>\n<h4>\nWhy Is A Form Closing?<br \/>\n<\/h4>\n<p>\nYou can use things like this (see the CloseReason members):\n<\/p>\n<pre>\r\n<code>if (e-&gt;CloseReason == System::Windows::Forms::CloseReason::UserClosing)<\/code><\/pre>\n<h4>\nSupressing Display Update Of A Form<br \/>\n<\/h4>\n<p>\nYou can&#39;t stop a form being painted, but you can do this:\n<\/p>\n<pre>\r\n<code>\r\n\tthis-&gt;SuspendLayout();\r\n\tMyControlName1-&gt;SuspendLayout();\r\n\tMyControlName2-&gt;SuspendLayout();\r\n\t...\r\n\tMyControlName1-&gt;ResumeLayout();\r\n\tMyControlName2-&gt;ResumeLayout();\r\n\tthis-&gt;ResumeLayout();\r\n<\/code><\/pre>\n<p>\nYou can also make specific controls invisible\n<\/p>\n<h4>\nDefault Accept and Cancel Buttons<br \/>\n<\/h4>\n<p>\nSet in the forms AcceptButton and CancelButton properties.<br \/>\nSet Dialog result for each button\n<\/p>\n<h4>\nReturning a Dialog Result<br \/>\n<\/h4>\n<p>\nYou can assign a dialog result value to buttons on the form in their properties.\n<\/p>\n<h4>\nStopping A Form \/ Application From Closing<br \/>\n<\/h4>\n<p>\nHandle the form&#39;s &#39;Closing&#39; event and set &#39;e.Cancel&#39; to &#39;True&#39; if you want to prevent the form from closing.<br \/>\ne-&gt;Cancel = true;<br \/>\nIf your going to present a message box, such as a &#39;do you want to save&#39; then you need to do the cancel first to stop the ap closing while waiting for the user input. Then afterwards do the close.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Opening a form #include &quot;FormName.h&quot; \/\/Add this at top of file frmConfiguration ^ConfigForm = gcnew frmConfiguration(); ConfigForm-&gt;PassedValue1 = &quot;This is a string I&#39;m passing&quot;; \/\/TO OPEN AS A DIALOG FORM: ConfigForm-&gt;ShowDialog(); \/\/or if (ConfigForm-&gt;ShowDialog() == System::Windows::Forms::DialogResult::OK) else if (ConfigForm-&gt;DialogResult == System::Windows::Forms::DialogResult::Cancel) \/\/TO OPEN NOT AS A DIALOG FORM: ConfigForm-&gt;Show(); Closing a form Close(); \/\/or this-&gt;Close(); [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[],"class_list":["post-172","post","type-post","status-publish","format-standard","hentry","category-forms"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/172","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/comments?post=172"}],"version-history":[{"count":8,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/172\/revisions"}],"predecessor-version":[{"id":1390,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/172\/revisions\/1390"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}