C Sharp .net中的窗口应用程序中的上下文菜单栏 [英] context menu strip in window application in c sharp .net

查看:59
本文介绍了C Sharp .net中的窗口应用程序中的上下文菜单栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void Rndmenustrip_Load(object sender, EventArgs e)
       {
           if (e.button==MouseButtons.Right)
           {
               this.contextMenuStrip1 = null;
           }
           else if (e.buttons==MouseButtons.Left)
         
           {

               this.contextMenuStrip1.Show(this , PointToScreen(new Point(120,120) ));
               //this.btn.ContextMenuStrip = this.btnConMenuStrip;
               //this.btn.ContextMenuStrip.Show(this, PointToScreen(new Point(e.X, e.Y)));
           }
       }


The problem is that this showing the error in underline portion
Am I doing something wrong?
Is there a better a way to achieve what I want?

推荐答案

您严重缺乏理解.
EventArgs没有ButtonMouseEventArgs没有.
You seriously lack understanding.
EventArgs doesn''t have Button, MouseEventArgs has.


除了Prera​​k解释的内容:为什么将null分配给上下文菜单?如果这样做,则必须重新创建并重新填充它,但是为什么呢.我看不到您这样做,所以我怀疑您在使用this.contextMenuStrip1.Show中的上下文菜单时会遇到异常.没有理由通过将null分配给变量来删除菜单.

看,我认为您现在不能开发UI.您似乎对变量,类,实例,对象生命周期等几乎一无所知.您需要回到最基础的知识上.在您完全熟悉基础知识之前,请不要返回UI.

—SA
In addition to what Prerak explained: why assigning null to context menu? If you do, you have to re-create and re-populate it from scratch, but why. I don''s see you do it, so I suspect you get exception when you use context menu in this.contextMenuStrip1.Show. There is not reason to remove menu by assigning null to the variable.

Look, I don''t think you can develop UI right now. It looks like you have very little idea of variables, classes, instances, object life cycle, etc. You need to get back to the very basics. Do not come back to UI until you''re perfectly comfortable with basics.

—SA


这篇关于C Sharp .net中的窗口应用程序中的上下文菜单栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆