We help IT Professionals succeed at work.

Determine which form has focus

Sheritlw
Sheritlw asked
on
Hi,
I am trying to implement .chm contextid help in my application and need to test what form currently has focus.
How do I determine which form, in a MDI application, has focus?
thanks
Comment
Watch Question

Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:

Author

Commented:
Yes, I already saw that article in my search.  However, it does not tell me how to use it to determine which form has focus.

For example,

Form currentForm = Form.ActiveForm;

If currentform = myformname then I want to show my help

I am very new to C# and am just trying to implement help within a MDI application by determining which form has the focus.  

Please provide an example.
Thank you
Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
Form currentForm = Form.ActiveForm;
String cfName = currentForm.Name;

if (cfName = "your form name")
{
   // show help ...
}

Author

Commented:
I receive an error that  project.AddEmpForm is a type but used like a variable
Below is what I have
private void btnHelp_Click(object sender, EventArgs e)
     
    {
      Form currentForm = Form.ActiveForm.ActiveMdiChild;
      String cfName = currentForm.Name;

      this.helpProvider1.SetHelpNavigator(this.btnHelp, System.Windows.Forms.HelpNavigator.TopicId);

     
      {
        if (cfname = "AddEmpForm")
          this.helpProvider1.SetHelpString(this, "html\\1150.htm");
      }
      //write here code
      //to go to design mode from Code press Shift+F7.
    }

Author

Commented:
The error was because cfname is case sensative (should have been cfName) and needed ==

Explore More ContentExplore courses, solutions, and other research materials related to this topic.