110,534
社区成员
发帖
与我相关
我的任务
分享
OutlookBarItem obi = new OutlookBarItem();//定义自定义类的对象
obi.contextMenu = this.contextMenuStrip1; //设置其值为contextMenuStrip1;
//obi.contextMenu.Show(); //可以直接show出来
this.ContextMenuStrip = obi.contextMenu;//也可以设置为ContextMenuStrip ,点右键show出来
#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
#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);