【发布时间】:2012-07-05 11:24:33
【问题描述】:
public void TapeMeasure(object sender, EventArgs e)
{
if (TrussManager.Truss != null)
{
Point containerPoint = trussEditor.PointToClient(Cursor.Position);
if (!trussEditor.MainMenu.CommandToolStrip.ClientRectangle.Contains(containerPoint))
execute command A
else
execute command B
}
}
这个事件是从
调用的ToolStripButton commandButton = new ToolStripButton("Tape", ConvertIconToImage(icon), TapeMeasure);
和
ToolStripMenuItem tsmi = new ToolStripMenuItem("Tape", ConvertIconToImage(icon), TapeMeasure);
(Winforms 应用程序)
我想知道我的光标何时不是我的工具条。然而,无论我的光标在哪里,上面的代码都会返回相同的结果。
此代码位于一个事件处理程序中,该处理程序可以从工具条上的按钮或上下文菜单上的按钮调用。如果在上下文菜单上调用它,我假设用户想要使用当前鼠标点。否则我希望用户去点击他们想要的点
有什么建议吗?
【问题讨论】:
-
Winforms 或 Wpf 以及这段代码在哪里
-
是什么触发了您的事件处理程序?鼠标移动?
-
我正在尝试复制,你在使用什么上下文菜单我无法向标准按钮添加一个按钮,以及上下文菜单分配给什么对象。到目前为止,您的代码正在运行
标签: c# winforms cursor contains windows-controls