{"id":170,"date":"2010-03-30T21:02:33","date_gmt":"2010-03-30T21:02:33","guid":{"rendered":"https:\/\/ibex.tech\/visualcpp\/?p=170"},"modified":"2022-02-17T06:24:05","modified_gmt":"2022-02-17T06:24:05","slug":"focus","status":"publish","type":"post","link":"https:\/\/ibex.tech\/visualcpp\/forms\/focus","title":{"rendered":"Focus"},"content":{"rendered":"<h4>Detecting Form Has Got Focus<\/h4>\n<p>Use the &#8216;Activated&#8217; event<\/p>\n<h4>Bring Form To Front<\/h4>\n<pre><code>\r\nthis-&gt;BringToFront();\r\n<\/code><\/pre>\n<h4>Does A Specific Control Have Focus?<\/h4>\n<pre><code>\r\nif (txtMyTextBox-&gt;ContainsFocus)\r\n<\/code><\/pre>\n<h4>Give an object on the form focus<\/h4>\n<pre><code>\r\n\t\/\/Use the objects focus property:\r\n\tObjectName-&gt;Focus();\r\n\t\/\/or give the form itself focus:\r\n\tfrmMyForm-&gt;Focus();\r\n<\/code><\/pre>\n<h4>Forcing a form to always be on top<\/h4>\n<p>Set the forms &#8216;Top Most&#8217; property to true.  This will keep the form above all forms including forms in other applicaitons, unless they have got focus and also have their top most property set.<\/p>\n<h4>Stopping Specific Form Objects From Being Selected By A User (e.g. text boxes being used as multiline labels)<\/h4>\n<p>Add this function<\/p>\n<pre><code>\r\n\t\/\/**************************************************\r\n\t\/\/**************************************************\r\n\t\/\/********** REMOVE FOCUS FROM TEXT BOXES **********\r\n\t\/\/**************************************************\r\n\t\/\/**************************************************\r\n\tprivate: System::Void ControlRemoveFocus(System::Object^  sender, System::Windows::Forms::MouseEventArgs^  e)\r\n\t{\r\n\t\t this-&gt;btnDone-&gt;Focus();\t\t\/\/Some object on the form that we'll give focus to instead\r\n\t}\r\n<\/code><\/pre>\n<p>Then or each control you don&#8217;t want to be selecable set its MouseDown event to be ControlRemoveFocus, which looks like this in code:<\/p>\n<pre><code>\r\n\tthis-&gt;txtMyTextBox-&gt;MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &amp;frmCellSetup::ControlRemoveFocus);\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Detecting Form Has Got Focus Use the &#8216;Activated&#8217; event Bring Form To Front this-&gt;BringToFront(); Does A Specific Control Have Focus? if (txtMyTextBox-&gt;ContainsFocus) Give an object on the form focus \/\/Use the objects focus property: ObjectName-&gt;Focus(); \/\/or give the form itself focus: frmMyForm-&gt;Focus(); Forcing a form to always be on top Set the forms &#8216;Top Most&#8217; [&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-170","post","type-post","status-publish","format-standard","hentry","category-forms"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/170","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=170"}],"version-history":[{"count":9,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":1135,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/posts\/170\/revisions\/1135"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/visualcpp\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}