Can you tell what menu item the mouse is pointing at? [modified]
-
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
-
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
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
-
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
Wouldn't MouseEnter / MouseLeave or whatever work?
-
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
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!
-
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
Wow. Thanks. I updated my code. I tried it but I got an undefined for the control.
Programmer Glenn Earl Graham Austin, TX
-
Wouldn't MouseEnter / MouseLeave or whatever work?
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
-
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!
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
-
Wow. Thanks. I updated my code. I tried it but I got an undefined for the control.
Programmer Glenn Earl Graham Austin, TX
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
-
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
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!
-
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!
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