2013-05-14 64 views
-1

我工作的代码编辑器,我做的MouseEvent为右击专门验证码:现在重载方法'Show'takes 2参数

if (e.Button == MouseButtons.Right) 
{    
     lbright.Show(Cursor.Position.X, Cursor.Position.Y); 
     lbright.BringToFront();    
} 

但问题是,每次我运行它的过载方法'错误出现并指向.Show(Cursor.Position.X, Cursor.Position.Y);

我该如何避免它?任何帮助将不胜感激,谢谢!

+0

'lbright'是什么类型? – 2013-05-14 07:34:45

+0

其列表框先生 – Elegiac 2013-05-14 07:36:00

+0

这没有任何意义。您正尝试在右键单击当前鼠标位置时显示一个列表框。你想在这里做什么? – 2013-05-14 07:37:20

回答

1

如果使用ContextMenu和使用超负荷.Show(Control, Point)与抵消,你应该得到你的菜单显示:

if (e.Button == MouseButtons.Right) 
{    
    // build a new ContextMenu with some menu items, let's use copy and paste 
    ContextMenu ctxRightClick = new ContextMenu(new MenuItem[] 
    { 
     new MenuItem("Copy"), 
     new MenuItem("Paste") 
    }); 

    // as per the documentation, the Point used by .Show is relative to the control you pass in so we calculate an offset from the mouse position 
    int xOffset = Cursor.Position.X - myForm.Location.X; 
    int yOffset = Cursor.Position.Y - myForm.Location.Y; 

    // now show the context menu as a child of myForm at the specified offset 
    ctxRightClick.Show(myForm, new Point(xOffset, yOffset)); 
} 
+0

感谢大师肖恩:D – Elegiac 2013-05-14 09:10:26

2

错误很明显:Control.Show()方法只有一个过载:一个没有参数。

如果要移动控件,请设置TopLeft属性。

+0

那我该怎么办那位先生?对不起,新手在这里。我的意思是我应该输入什么特定的代码 – Elegiac 2013-05-14 07:38:19

+0

你想达到什么目的? – jAC 2013-05-14 07:38:59

+0

@Elegiac没有“输入的特定代码”。你正在编程什么,所以你有一个想法你想要做什么。如果你解释你的想法(在你的问题中,而不是在评论中),也许有人可以告诉你一些事情来帮助你解决你的问题。 – CodeCaster 2013-05-14 07:39:39

3

您正在尝试显示上下文菜单。使用为该任务设计的课程:ContextMenu

这个类有一个Show方法,可以让你位置的菜单:Show(Control, Point)

+0

这样的东西先生:rightcontext.Show(Control,Point); ?我在MouseDown事件中编写代码,但是错误Dte.Show(System.Windows.Forms.Control,SYstem.Drawing.Point)'必须声明一个实体,因为它没有标记为抽象,外部或部分。 – Elegiac 2013-05-14 07:53:48

+0

@Elegiac:正如我告诉你的那样:阅读文档并检查样本。他们清楚地展示了如何使用该方法。 – 2013-05-14 07:54:47

+0

先生,我尝试它,它的工作!问题是我仍然得到显示超载错误,我尝试所有代码在这里:http://stackoverflow.com/questions/8199019/how-do-i-correctly-position-a-context-menu-when-i-right -click-a-datagridviews-c但仍然存在这个错误:(我该怎么做才能删除那个错误?谢谢先生 – Elegiac 2013-05-14 08:09:50

0

从我从你的问题搞定了,我想这可能帮助

lbright.Top=Cursor.Position.X; 
lbright.Left=Cursor.Position.Y; 
lbright.Show();