日期:2014-05-20  浏览次数:20725 次

如何确定dotnetbar中的鼠标单击坐标?
我用dotnetbar做了一个可停界面,然后将treeview控件加入其中的一个可停靠窗体上,我想实现的功能就是----在treeview控件上单击右键弹出一个快捷菜单,菜单出现的位置为鼠标单击的位置。可是我不知道怎样才能实现,菜单出现的位置总是不能让人满意,只要改变窗体位置,快捷菜单出现位置就出错。    
下面是我实验过的一些代码:    
第一种:    
private     void     treeView_projInfo_MouseDown(object     sender,     System.Windows.Forms.MouseEventArgs     e)    
{    
int     x,y;    
x=e.X+this.Location.X+this.leftBar.Location.X+this.treeView_projInfo.Location.X-30;     //leftBar是一个可停靠窗体
y=e.Y+this.Location.Y+this.leftBar.Location.Y+this.treeView_projInfo.Location.Y+100;    
if(e.Button==MouseButtons.Right)    
      this.popu_treeView.Popup(x,y);    
}    
第二种    
private     void     treeView_projInfo_MouseDown(object     sender,     System.Windows.Forms.MouseEventArgs     e)    
{    
int     x,y;    
x=e.X+this.Location.X+this.treeView_projInfo.Location.X-30;    
y=e.Y+this.Location.Y+this.treeView_projInfo.Location.Y+100;    
if(e.Button==MouseButtons.Right)    
      this.popu_treeView.Popup(x,y);    
}    
第三种    
private     void     treeView_projInfo_MouseDown(object     sender,     System.Windows.Forms.MouseEventArgs     e)    
{    
int     x,y;    
x=e.X+this.panelDockContainer1.Left;   //panelDockContainer1是可停靠窗体的面板,我也不知道它和leftBar具体的关系,但是它们是被绑定在一起的
y=e.Y+this.panelDockContainer1.Top;    
if(e.Button==MouseButtons.Right)    
      this.popu_treeView.Popup(x,y);    
}    
这些代码都有一个毛病,只要移动整个窗体位置,或者是改变可停靠窗体位置,快捷菜单出现位置就不正确了,希望有高手替我解答,在下十分感谢!    


------解决方案--------------------
菜单的位置一般来说是以屏幕为准的,所以,你可以如下得到:

Point p = Cursor.Position;


Point p = Control.MousePosition;