component 类本来就没有ContextMenu属性,自己定义?
给下代码?

解决方案 »

  1.   

    用的一个第三方控件,想修改下,但是没成功 #region OutlookBar Item class
    [ToolboxItem(false)]
    public class OutlookBarItem : Component
    {
    #region Class variables
    string text;
            int imageIndex = -1;
    object tag;
            private ContextMenuStrip  _contextMenu;
            public ContextMenuStrip  contextMenu
            {
                get { return _contextMenu; }
                set { _contextMenu = value; }
            } #endregion #region Events
    #endregion

    #region Constructors
    public OutlookBarItem(string text, int ImageIndex)
    {
    this.text = text;
    this.imageIndex = ImageIndex;
    } public OutlookBarItem(string text, int imageIndex, object tag)
    {
    this.text = text;
    this.imageIndex = imageIndex;
    tag = tag;
    } public OutlookBarItem()
    {
    // To support designer
    imageIndex = -1;
    } #endregion #region Overrides
    #endregion #region Methods 
    #endregion

    #region Properties
    public int ImageIndex
    {
    set { imageIndex = value; }
    get { return imageIndex; }
    } public string Text
    {
    set { text = value; }
    get { return text; }
    } public object Tag
    {
    set { tag = value; }
    get { return tag; }
    } #endregion #region Implementation
    #endregion
    }
    #endregion
    窗体里面的代码
     
                OutlookBarBand outlookShortcutsBand = new OutlookBarBand("权限管理");
                outlookShortcutsBand.ContextMenu = null;
                outlookShortcutsBand.SmallImageList = this.imageList1;
                outlookShortcutsBand.LargeImageList = this.imageList1;
                outlookShortcutsBand.Items.Add(new OutlookBarItem("用户管理", 0));
                outlookShortcutsBand.Items.Add(new OutlookBarItem("机构管理", 1));
                outlookShortcutsBand.Items.Add(new OutlookBarItem("角色管理", 2));
                MenuItem menuItem1 = new MenuItem("测试一");
                MenuItem menuItem2 = new MenuItem("测试二");
                MenuItem menuItem3 = new MenuItem("测试三");
            
                menuItem1.Click += new EventHandler(menuItem1_click);
                menuItem2.Click += new EventHandler(menuItem2_click);
                menuItem3.Click += new EventHandler(menuItem3_click);
              
                outlookShortcutsBand.Items[0].ContextMenu = new ContextMenu(new MenuItem[] { menuItem1, menuItem2, menuItem3 });
                outlookShortcutsBand.Background = SystemColors.AppWorkspace;
                outlookShortcutsBand.TextColor = Color.White;
                outlookBar1.Bands.Add(outlookShortcutsBand);
      

  2.   

    控件里面的代码有点问题
    是这个#region OutlookBar Item class
    [ToolboxItem(false)]
    public class OutlookBarItem : Component
    {
    #region Class variables
    string text;
            int imageIndex = -1;
    object tag;
            private ContextMenu  _contextMenu;
            public ContextMenu  contextMenu
            {
                get { return _contextMenu; }
                set { _contextMenu = value; }
            } #endregion #region Events
    #endregion

    #region Constructors
    public OutlookBarItem(string text, int ImageIndex)
    {
    this.text = text;
    this.imageIndex = ImageIndex;
    } public OutlookBarItem(string text, int imageIndex, object tag)
    {
    this.text = text;
    this.imageIndex = imageIndex;
    tag = tag;
    } public OutlookBarItem()
    {
    // To support designer
    imageIndex = -1;
    } #endregion #region Overrides
    #endregion #region Methods 
    #endregion

    #region Properties
    public int ImageIndex
    {
    set { imageIndex = value; }
    get { return imageIndex; }
    } public string Text
    {
    set { text = value; }
    get { return text; }
    } public object Tag
    {
    set { tag = value; }
    get { return tag; }
    } #endregion #region Implementation
    #endregion
    }
    #endregion
      

  3.   

    第三方控件的源代码在这里可以下载
    http://www.cnblogs.com/sousou/
    那个哥们修改好了告诉一声,谢谢
      

  4.   


    你拖个contextMenuStrip1,加几个项,然后写如下代码,我测试了是可以的 OutlookBarItem obi = new OutlookBarItem();//定义自定义类的对象
     obi.contextMenu = this.contextMenuStrip1; //设置其值为contextMenuStrip1;
     //obi.contextMenu.Show();  //可以直接show出来
     this.ContextMenuStrip = obi.contextMenu;//也可以设置为ContextMenuStrip ,点右键show出来