C#模仿Windows可折叠导航栏
先上张效果图,依次为全展开图,部分折叠图,全部折叠图代码下载:/2012/0509/20120509024345964.rar
时间仓促,功能相对简单,也未经过详细测试,不支持设计期操作,这里提供思路给大家,有时间完善吧,上代码:
代码文件介绍
NavBar.cs 导航栏主体,继承自 Panel
NavGroup.cs NavBar中的分组,即(控制面板,我的电脑等),继承自Control
NavBarItem.cs 分组中的小项(即区域选项,字体等),继承自Control
NavBarButton.cs 导航栏主体右边的圆形按钮
NavGroupCollection.cs 分组的集合
NavBarItemCollection.cs 分组中小项的集合
NavGroupState.cs 组的状态,收缩还是展开
NavBar.cs
[csharp]
using System;
using System.Collections.Generic;
using System.Drawing.Design;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class NavBar : Panel
{
private NavGroupCollection _groups;
public NavGroupCollection Groups
{
get { return this._groups; }
}
public NavGroup this[int index]
{
get
{
if (index > -1)
return this._groups[index];
else
return null;
}
}
private int _selectedIndex = -1;
/// <summary>
/// 选择组的索引
/// </summary>
[DefaultValue(-1)]
public int SelectedIndex
{
get { return this._selectedIndex; }
set
{
this._selectedIndex = value;
this.SelectGroup(value);
}
}
private int _groupSpace = 20;
/// <summary>
/// Group间距
/// </summary>
public int GroupSpace
{
get { return this._groupSpace; }
set { this._groupSpace = value; }
}
private int _groupMargin = 5;
/// <summary>
/// Group边距
/// </summary>
public int GroupMargin
{
get { return this._groupMargin; }
set { this._groupMargin = value; }
}
private ImageList _smallImageList;
/// <summary>
/// 设置图像列表
/// </summary>
public ImageList SmallImageList
{
get { return this._smallImageList; }
set { this._smallImageList = value; }
}
public NavBar()
{
InitializeComponent();
this.BackColor = Color.FromArgb(112, 140, 225);
this._groups = new NavGroupCollection(this);
this.AutoScroll = true;
}
/// <summary>
/// 根据添加的项,布局
/// </summary>
/// <param name="item"></param>
public void SetLayOut(NavGroup item)
{
this.SuspendLayout();
this.Controls.Add(item);
if (this._groups.Count =
补充:软件开发 , C# ,