Contextmenustrip显示空白项目.. [英] Contextmenustrip displays blank item..

查看:179
本文介绍了Contextmenustrip显示空白项目..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在树视图节点右键单击打开contextmenustrip,

但是当我在contextmenustrip上按下键时,选择向下移动,最后它显示为空白item,

为什么会这样。

某些contextmenustrip项目可见= false。

当contextmenustrip的所有项目都可见时,contextmenustrip正常工作,

但如果某些contextmenustrip项目可见= false它最后会显示空白项目。



我已经快速但是我无法粘贴它在这里...: - (

Hi,
I am opening contextmenustrip on treeview node right click,
but when i press down key on contextmenustrip, selection moves down & at last it is showing blank item,
why it is happening.
Some contextmenustrip item are visible=false.
When all items of contextmenustrip are visible, contextmenustrip works properly,
but if some contextmenustrip item are visible=false it shows blank item at last.

I have snap but i am unble to paste it here...:-(

推荐答案

在一个简单的实验中,我无法复制你描述的行为。



1.在表格上放置一个TreeView



2.添加一些节点



3.向Form添加一个ContextMenuStrip。添加四个项目。



4.将TreeView的ContextMenuStrip属性设置为ContextMenuStrip



5.在NodeMouseClick EventHandler中e TreeView:



In a simple experiment, I am unable to duplicate the behavior you describe.

1. put a TreeView on a Form

2. add some Nodes

3. add a ContextMenuStrip to the Form. Add four items.

4. set the TreeView's ContextMenuStrip Property to the ContextMenuStrip

5. in the NodeMouseClick EventHandler for the TreeView:

private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
    contextMenuStrip1.Items[0].Visible = (! (e.Node.Name == "Node0")); 
    contextMenuStrip1.Items[2].Visible = (! (e.Node.Name == "Node2")); 
}

当我右键单击Node0或Node2时,我看不到任何空白项目,并且向上/向下箭头键按预期工作。

I see no blank items when I right-context-click on "Node0" or "Node2," and the up/down arrow keys work as expected.


我没有找到为什么在我的项目中出现上述问题: -

但我发现以下解决方案: -



1.设置ContextMenustrip的以下属性: -

I didn't found why above problem happening in my project:-
But i found following solution on it:-

1.Set following property of ContextMenustrip:-
contextMenuStrip1.AutoSize = false;



2.Register contextMenuStrip开设的活动如下: -


2.Register contextMenuStrip Opened event as follows:-

private void contextMenuStrip1_Opened(object sender, EventArgs e)
      {
          int iHeight = 0;
          foreach (ToolStripMenuItem t in contextMenuStrip1.Items)
          {
              if (t.Visible)
                  iHeight += t.Size.Height;
          }
          contextMenuStrip1.Height = iHeight + 5;
      }


这篇关于Contextmenustrip显示空白项目..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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