Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 控件边界内的光标_C#_Winforms_Cursor_Contains_Windows Controls - Fatal编程技术网

C# 控件边界内的光标

C# 控件边界内的光标,c#,winforms,cursor,contains,windows-controls,C#,Winforms,Cursor,Contains,Windows Controls,此事件从调用 public void TapeMeasure(object sender, EventArgs e) { if (TrussManager.Truss != null) { Point containerPoint = trussEditor.PointToClient(Cursor.Position); if (!trussEditor.MainMenu.CommandToolStrip.ClientRectangle.

此事件从调用

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
     }
  }

(Winforms应用程序)

我想知道光标何时不是Toolstrip。但是,无论光标在哪里,上面的代码都会不断返回相同的结果

此代码位于从Toolstrip上的按钮或contextmenu上的按钮调用的eventhandler中。如果在上下文菜单上调用它,我假设用户想要使用当前鼠标点。否则,我希望用户点击他们想要的点


有什么建议吗?

因为您正在使用MouseClick事件来启动您的方法,所以Click事件的Sender对象将具有发起该事件的对象。在本例中,我只确定发送者的类型,因为一个是ToolStripButton,另一个是MenuItem。正如我在聊天中提到的,光标点在不断更新,我认为这是造成您问题的原因

本例将确定哪个对象生成ClickEvent并运行相应的方法

ToolStripMenuItem tsmi = new ToolStripMenuItem("Tape", ConvertIconToImage(icon), TapeMeasure);
本例将考虑ContextMenu的位置,并采用与单击工具栏中包含的按钮相同的方法

public void TapeMeasure(object sender, EventArgs e) 
{ 
    if (TrussManager.Truss != null) 
    { 
        System.Type sysType = sender.GetType();

        if (!(sysType.Name == "ToolStripButton"))
            //execute command A 
        else 
            //execute command B 
    } 
} 

由于您正在使用MouseClick事件来启动您的方法,因此Click事件的Sender对象将具有发起该事件的对象。在本例中,我只确定发送者的类型,因为一个是ToolStripButton,另一个是MenuItem。正如我在聊天中提到的,光标点在不断更新,我认为这是造成您问题的原因

本例将确定哪个对象生成ClickEvent并运行相应的方法

ToolStripMenuItem tsmi = new ToolStripMenuItem("Tape", ConvertIconToImage(icon), TapeMeasure);
本例将考虑ContextMenu的位置,并采用与单击工具栏中包含的按钮相同的方法

public void TapeMeasure(object sender, EventArgs e) 
{ 
    if (TrussManager.Truss != null) 
    { 
        System.Type sysType = sender.GetType();

        if (!(sysType.Name == "ToolStripButton"))
            //execute command A 
        else 
            //execute command B 
    } 
} 

Winforms或Wpf以及此代码位于何处触发eventhandler的是什么?MouseMove?我正在尝试复制,您使用什么作为上下文菜单?我无法将按钮添加到标准按钮,也无法将上下文菜单指定给哪个对象。到目前为止,您的代码正在运行WinForms或Wpf,并且此代码位于何处触发您的eventhandler?MouseMove?我正在尝试复制,您使用什么作为上下文菜单?我无法将按钮添加到标准按钮,也无法将上下文菜单指定给哪个对象。到目前为止,您的代码正在运行