* UINavBar:增加下拉菜单可设置自动高度或者固定高度,可显示ImageList绑定的图标

This commit is contained in:
Sunny 2021-01-19 21:42:34 +08:00
parent 9a6732ee31
commit edb1e657f7
7 changed files with 20 additions and 2 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -47,6 +47,7 @@
this.uiButton1.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiButton1.Location = new System.Drawing.Point(30, 57);
this.uiButton1.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton1.Name = "uiButton1";
this.uiButton1.Size = new System.Drawing.Size(232, 35);
this.uiButton1.TabIndex = 0;
@ -56,13 +57,14 @@
//
this.uiContextMenuStrip1.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiContextMenuStrip1.Name = "uiContextMenuStrip1";
this.uiContextMenuStrip1.Size = new System.Drawing.Size(61, 4);
this.uiContextMenuStrip1.Size = new System.Drawing.Size(181, 26);
//
// uiButton2
//
this.uiButton2.Cursor = System.Windows.Forms.Cursors.Hand;
this.uiButton2.Font = new System.Drawing.Font("微软雅黑", 12F);
this.uiButton2.Location = new System.Drawing.Point(294, 57);
this.uiButton2.MinimumSize = new System.Drawing.Size(1, 1);
this.uiButton2.Name = "uiButton2";
this.uiButton2.Size = new System.Drawing.Size(232, 35);
this.uiButton2.TabIndex = 1;

View File

@ -255,6 +255,7 @@ namespace Sunny.UI
}
[DefaultValue(null)]
[Browsable(false)]
[Description("下拉菜单图片列表"), Category("SunnyUI")]
public ImageList DropMenuImageList
{
@ -505,10 +506,12 @@ namespace Sunny.UI
NavBarMenu.Style = UIStyles.Style;
NavBarMenu.Items.Clear();
NavBarMenu.ImageList = ImageList;
foreach (TreeNode node in Nodes[SelectedIndex].Nodes)
{
ToolStripMenuItem item = new ToolStripMenuItem(node.Text) { Tag = node };
item.Click += Item_Click;
if (ImageList != null) item.ImageIndex = node.ImageIndex;
NavBarMenu.Items.Add(item);
if (node.Nodes.Count > 0)
@ -528,13 +531,25 @@ namespace Sunny.UI
{
item.AutoSize = false;
item.Width = NavBarMenu.Width - 1;
item.Height = 30;
if (!DropDownItemAutoHeight)
{
item.Height = DropDownItemHeight;
}
}
NavBarMenu.CalcHeight();
NavBarMenu.Show(this, NodeMenuLeft(SelectedIndex), Height);
}
[DefaultValue(30)]
[Description("下拉菜单节点高度"), Category("SunnyUI")]
public int DropDownItemHeight { get; set; } = 30;
[DefaultValue(false)]
[Description("下拉菜单节点自动高度"), Category("SunnyUI")]
public bool DropDownItemAutoHeight { get; set; } = false;
private void Item_Click(object sender, EventArgs e)
{
ToolStripMenuItem item = (ToolStripMenuItem)sender;
@ -559,6 +574,7 @@ namespace Sunny.UI
foreach (TreeNode childNode in node.Nodes)
{
ToolStripMenuItem childItem = new ToolStripMenuItem(childNode.Text) { Tag = childNode };
if (ImageList != null) childItem.ImageIndex = childNode.ImageIndex;
childItem.Click += Item_Click;
item.DropDownItems.Add(childItem);