Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Can you tell what menu item the mouse is pointing at? [modified]

Can you tell what menu item the mouse is pointing at? [modified]

Scheduled Pinned Locked Moved C#
csharpc++htmlwinformshelp
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    earlgraham
    wrote on last edited by
    #1

    In C# how would you do this? Can you? I am working in C++/CLI with Windows Forms. No one in the C++/CLI forum was aware of a way to tell where the mouse is pointing when the helpprovider event is called. I want to have my compiled html help point to a topic specific to where the mouse is pointing (like as a menu item) but I can't seem to determine which control the mouse is hovering over. My C++/CLI code is below.

    private: System::Void FrmMain_HelpRequested(System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent)
    {
    Point pt = this->PointToClient(hlpevent->MousePos);
    Control^ requestingControl = dynamic_cast(sender);
    Control ^ctrl = this->pt;GetChildAtPoint(pt);
    Control ^ctrl2 = this->pt;ActiveControl;
    Point ptMI = this->menuMainForm->PointToClient(hlpevent->MousePos);
    Control ^ctrlMI = this->menuMainForm->GetChildAtPoint(ptMI);
    Point ptMenuHelp = this->miHelp->DropDown->PointToClient(hlpevent->MousePos);
    Control ^ctrlMenuHelp = this->miHelp->DropDown->GetChildAtPoint(ptMenuHelp);
    if( File::Exists(this->pt;helpProvider->HelpNamespace ) == true)
    {
    Help::ShowHelp(this, this->helpProvider->HelpNamespace);
    }
    }

    ctrl is the form itself and crtl2 is the last active mdichild in my application. requestingControl returns the form (same as ctrl)and not the item the mouse is over. ctrlMI and ctrlMenuHelp are undefined. Hope someone can help :sigh:

    Programmer Glenn Earl Graham Austin, TX

    modified on Monday, January 07, 2008 4:03:51 PM

    J P L 3 Replies Last reply
    0
    • E earlgraham

      In C# how would you do this? Can you? I am working in C++/CLI with Windows Forms. No one in the C++/CLI forum was aware of a way to tell where the mouse is pointing when the helpprovider event is called. I want to have my compiled html help point to a topic specific to where the mouse is pointing (like as a menu item) but I can't seem to determine which control the mouse is hovering over. My C++/CLI code is below.

      private: System::Void FrmMain_HelpRequested(System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent)
      {
      Point pt = this->PointToClient(hlpevent->MousePos);
      Control^ requestingControl = dynamic_cast(sender);
      Control ^ctrl = this->pt;GetChildAtPoint(pt);
      Control ^ctrl2 = this->pt;ActiveControl;
      Point ptMI = this->menuMainForm->PointToClient(hlpevent->MousePos);
      Control ^ctrlMI = this->menuMainForm->GetChildAtPoint(ptMI);
      Point ptMenuHelp = this->miHelp->DropDown->PointToClient(hlpevent->MousePos);
      Control ^ctrlMenuHelp = this->miHelp->DropDown->GetChildAtPoint(ptMenuHelp);
      if( File::Exists(this->pt;helpProvider->HelpNamespace ) == true)
      {
      Help::ShowHelp(this, this->helpProvider->HelpNamespace);
      }
      }

      ctrl is the form itself and crtl2 is the last active mdichild in my application. requestingControl returns the form (same as ctrl)and not the item the mouse is over. ctrlMI and ctrlMenuHelp are undefined. Hope someone can help :sigh:

      Programmer Glenn Earl Graham Austin, TX

      modified on Monday, January 07, 2008 4:03:51 PM

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Hi Glenn I tried out a few things and here's what I came up with. If you've got a MenuStrip (e.g. File, Edit, View, etc.) and you're trying to see if the mouse is over a particular menu item (e.g. the File->Exit), you can do it like this:

      Point localPoint = fileMenuItem.DropDown.PointToClient(hlpevent.MousePos);
      if(exitMenuItem == fileMenuItem.DropDown.GetItemAt(localPoint)) // then we're over the exit menu item!

      Does this help?

      Tech, life, family, faith: Give me a visit. I'm currently blogging about: What this world needs... (Video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

      E 1 Reply Last reply
      0
      • E earlgraham

        In C# how would you do this? Can you? I am working in C++/CLI with Windows Forms. No one in the C++/CLI forum was aware of a way to tell where the mouse is pointing when the helpprovider event is called. I want to have my compiled html help point to a topic specific to where the mouse is pointing (like as a menu item) but I can't seem to determine which control the mouse is hovering over. My C++/CLI code is below.

        private: System::Void FrmMain_HelpRequested(System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent)
        {
        Point pt = this->PointToClient(hlpevent->MousePos);
        Control^ requestingControl = dynamic_cast(sender);
        Control ^ctrl = this->pt;GetChildAtPoint(pt);
        Control ^ctrl2 = this->pt;ActiveControl;
        Point ptMI = this->menuMainForm->PointToClient(hlpevent->MousePos);
        Control ^ctrlMI = this->menuMainForm->GetChildAtPoint(ptMI);
        Point ptMenuHelp = this->miHelp->DropDown->PointToClient(hlpevent->MousePos);
        Control ^ctrlMenuHelp = this->miHelp->DropDown->GetChildAtPoint(ptMenuHelp);
        if( File::Exists(this->pt;helpProvider->HelpNamespace ) == true)
        {
        Help::ShowHelp(this, this->helpProvider->HelpNamespace);
        }
        }

        ctrl is the form itself and crtl2 is the last active mdichild in my application. requestingControl returns the form (same as ctrl)and not the item the mouse is over. ctrlMI and ctrlMenuHelp are undefined. Hope someone can help :sigh:

        Programmer Glenn Earl Graham Austin, TX

        modified on Monday, January 07, 2008 4:03:51 PM

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        Wouldn't MouseEnter / MouseLeave or whatever work?

        E 1 Reply Last reply
        0
        • E earlgraham

          In C# how would you do this? Can you? I am working in C++/CLI with Windows Forms. No one in the C++/CLI forum was aware of a way to tell where the mouse is pointing when the helpprovider event is called. I want to have my compiled html help point to a topic specific to where the mouse is pointing (like as a menu item) but I can't seem to determine which control the mouse is hovering over. My C++/CLI code is below.

          private: System::Void FrmMain_HelpRequested(System::Object^ sender, System::Windows::Forms::HelpEventArgs^ hlpevent)
          {
          Point pt = this->PointToClient(hlpevent->MousePos);
          Control^ requestingControl = dynamic_cast(sender);
          Control ^ctrl = this->pt;GetChildAtPoint(pt);
          Control ^ctrl2 = this->pt;ActiveControl;
          Point ptMI = this->menuMainForm->PointToClient(hlpevent->MousePos);
          Control ^ctrlMI = this->menuMainForm->GetChildAtPoint(ptMI);
          Point ptMenuHelp = this->miHelp->DropDown->PointToClient(hlpevent->MousePos);
          Control ^ctrlMenuHelp = this->miHelp->DropDown->GetChildAtPoint(ptMenuHelp);
          if( File::Exists(this->pt;helpProvider->HelpNamespace ) == true)
          {
          Help::ShowHelp(this, this->helpProvider->HelpNamespace);
          }
          }

          ctrl is the form itself and crtl2 is the last active mdichild in my application. requestingControl returns the form (same as ctrl)and not the item the mouse is over. ctrlMI and ctrlMenuHelp are undefined. Hope someone can help :sigh:

          Programmer Glenn Earl Graham Austin, TX

          modified on Monday, January 07, 2008 4:03:51 PM

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #4

          Hi, I have not used it myself, but the way I understand MSDN on Control.HelpRequested event you should add an event to every Control for which you want to provide help; then in the HelpRequested event handler the sender parameter points to the Control that currently needs to show help. :)

          Luc Pattyn [Forum Guidelines] [My Articles]


          Happy 2008!


          E 1 Reply Last reply
          0
          • J Judah Gabriel Himango

            Hi Glenn I tried out a few things and here's what I came up with. If you've got a MenuStrip (e.g. File, Edit, View, etc.) and you're trying to see if the mouse is over a particular menu item (e.g. the File->Exit), you can do it like this:

            Point localPoint = fileMenuItem.DropDown.PointToClient(hlpevent.MousePos);
            if(exitMenuItem == fileMenuItem.DropDown.GetItemAt(localPoint)) // then we're over the exit menu item!

            Does this help?

            Tech, life, family, faith: Give me a visit. I'm currently blogging about: What this world needs... (Video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

            E Offline
            E Offline
            earlgraham
            wrote on last edited by
            #5

            Wow. Thanks. I updated my code. I tried it but I got an undefined for the control.

            Programmer Glenn Earl Graham Austin, TX

            J 1 Reply Last reply
            0
            • P PIEBALDconsult

              Wouldn't MouseEnter / MouseLeave or whatever work?

              E Offline
              E Offline
              earlgraham
              wrote on last edited by
              #6

              If you wanted an event for every menuitem. I was hoping there was a cleaner way.

              PIEBALDconsult wrote:

              Wouldn't MouseEnter / MouseLeave or whatever work?

              Programmer Glenn Earl Graham Austin, TX

              1 Reply Last reply
              0
              • L Luc Pattyn

                Hi, I have not used it myself, but the way I understand MSDN on Control.HelpRequested event you should add an event to every Control for which you want to provide help; then in the HelpRequested event handler the sender parameter points to the Control that currently needs to show help. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Happy 2008!


                E Offline
                E Offline
                earlgraham
                wrote on last edited by
                #7

                For the menu dropdown items there is no event for the helpprovider. There is for the file menu itself but it does not tell you which menu item you are currently looking at.

                Luc Pattyn wrote:

                I have not used it myself, but the way I understand MSDN on Control.HelpRequested event you should add an event to every Control for which you want to provide help; then in the HelpRequested event handler the sender parameter points to the Control that currently needs to show help.

                Programmer Glenn Earl Graham Austin, TX

                L 1 Reply Last reply
                0
                • E earlgraham

                  Wow. Thanks. I updated my code. I tried it but I got an undefined for the control.

                  Programmer Glenn Earl Graham Austin, TX

                  J Offline
                  J Offline
                  Judah Gabriel Himango
                  wrote on last edited by
                  #8

                  I'm not sure I understand. You got null back for the control returned?

                  Tech, life, family, faith: Give me a visit. I'm currently blogging about: What this world needs... (Video) The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

                  1 Reply Last reply
                  0
                  • E earlgraham

                    For the menu dropdown items there is no event for the helpprovider. There is for the file menu itself but it does not tell you which menu item you are currently looking at.

                    Luc Pattyn wrote:

                    I have not used it myself, but the way I understand MSDN on Control.HelpRequested event you should add an event to every Control for which you want to provide help; then in the HelpRequested event handler the sender parameter points to the Control that currently needs to show help.

                    Programmer Glenn Earl Graham Austin, TX

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #9

                    OK, I see the problem now: MenuItem is not a Control. However MainMenu and ContextMenu are, so you could enumerate their menu items recursively to find the one that is currently selected (MenuItem.Selected property). Not sure what will happen when you move the mouse up or down, selecting another menu item. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Happy 2008!


                    E 1 Reply Last reply
                    0
                    • L Luc Pattyn

                      OK, I see the problem now: MenuItem is not a Control. However MainMenu and ContextMenu are, so you could enumerate their menu items recursively to find the one that is currently selected (MenuItem.Selected property). Not sure what will happen when you move the mouse up or down, selecting another menu item. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      Happy 2008!


                      E Offline
                      E Offline
                      earlgraham
                      wrote on last edited by
                      #10

                      Thank You very much. It works like a champ! Here is my final code (c++/CLI).

                      for each ( ToolStripMenuItem ^tmpMS in this->menuMainForm->Items )
                      {
                      for each ( ToolStripItem ^tmpCntl in tmpMS->DropDownItems )
                      {
                      if (tmpCntl)
                      {
                      if ( tmpCntl->Selected )
                      String ^tmpCntlName = tmpCntl->Name;
                      OpenHelpForMenuItem(tmpCntlName);
                      }
                      }
                      }

                      Programmer Glenn Earl Graham Austin, TX

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups