Detecting Form Has Got Focus
Use the ‘Activated’ event
Bring Form To Front
this->BringToFront();
Does A Specific Control Have Focus?
if (txtMyTextBox->ContainsFocus)
Give an object on the form focus
//Use the objects focus property:
ObjectName->Focus();
//or give the form itself focus:
frmMyForm->Focus();
Forcing a form to always be on top
Set the forms ‘Top Most’ 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.
Stopping Specific Form Objects From Being Selected By A User (e.g. text boxes being used as multiline labels)
Add this function
//**************************************************
//**************************************************
//********** REMOVE FOCUS FROM TEXT BOXES **********
//**************************************************
//**************************************************
private: System::Void ControlRemoveFocus(System::Object^ sender, System::Windows::Forms::MouseEventArgs^ e)
{
this->btnDone->Focus(); //Some object on the form that we'll give focus to instead
}
Then or each control you don’t want to be selecable set its MouseDown event to be ControlRemoveFocus, which looks like this in code:
this->txtMyTextBox->MouseDown += gcnew System::Windows::Forms::MouseEventHandler(this, &frmCellSetup::ControlRemoveFocus);
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.