EasyCode左侧导航栏问题
下了个EasyCode来试用研究,生成了个模块,就是关于左侧导航栏,发现有个问题。如果栏中的项台多时候,它没有条栏拉动,或者上下键去翻滚。如图。对于这个问题,谁有研究过?
应该如何修改,可以有上下拉滚功能。
代码如下:
导航栏 C#
public NavBar()
{
InitializeComponent();
////示例:根据用户角色修改导航条
//if(!NowUser.IsAdministrator) //如果不是管理员
//{
// NavButtonGroup.RemoveAt(2); //删除导航栏中第3组导般条
// NavButtonGroup[1].ImageButtons.RemoveAt(0); //删除导航栏中第2组导般条中的第1个图像按钮
//}
InitNavBar(); // 初始化导航栏,该方法必须在NavButtonGroup重新调整后执行
}
/// <summary>
/// 说明:导航栏初始的功能模块列表,可以通过定义此列表设置导航栏中的导航条及图片按扭。
/// 注意:这里定义的是一个私有的List类型变量NavButtonGroup,并不是一个私有的函数方法。
/// </summary>
private List<NavBar.ButtonGroup> NavButtonGroup = new List<NavBar.ButtonGroup>()
{
new ButtonGroup("欢迎使用")
{
ImageButtons = new List<ImageButton>()
{
new ImageButton("欢迎使用","Main",Resources.NavBtnMain),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee),
new ImageButton("员工信息管理","ManageEmployee",Resources.NavBtnManageEmployee)
}
} ,
new ButtonGroup("系统设置")
{
ImageButtons = new List<ImageButton>()
{
new ImageButton("部门管理","ManageDepartment",Resources.NavBtnManageDepartment)
}
} ,
new ButtonGroup("退出系统")
{
}
};
#region 导航栏类中的相关属性与方法
public delegate void ButtonClickHander(object sender, string targetModule);
public event EventHandler QuitSystemClick;
public event ButtonClickHander ImageButtonClick;
/// <summary>
/// 初始化导航栏
/// </summary>
private void InitNavBar()
{
this.Dock = DockStyle.Left;
int barHeight = 22;
for (int n = 0; n < NavButtonGroup.Count; n++)
{
ButtonGroup buttonGroup = NavButtonGroup[n];
buttonGroup.Left = 2;
buttonGroup.Tag = n;
buttonGroup.TitleBarClick += new EventHandler(TitleBar_Click);
buttonGroup.ImageButtonClick += new ButtonClickHander(ImageButton_Click);
buttonGroup.InitImageButtons();
PnlBackGround.Controls.Add(buttonGroup);
}
PnlBottomLine.Top = PnlBackGround.Height - (NavButtonGroup.Count - CurrentGroupIndex - 1) * barHeight;
ResetNavBar();
}
/// <summary>
/// 重新设置导航栏的布局。
/// </summary>
private void ResetNavBar()
{
int barHeight = 22;
for (int n = 0; n < NavButtonGroup.Count; n++)
{
ButtonGroup buttonGroup = NavButtonGroup[n];
if (n <= CurrentGroupIndex)
{
buttonGroup.Top = 1 + n * barHeight;
}
else
{
buttonGroup.Top = PnlBackGround.Height - (NavButtonGroup.Count - n) * barHeight;
}
if (n == CurrentGroupIndex)
{
buttonGroup.Height = PnlBackGround.Height - (NavButtonGroup.Count - 1) * barHeight;
}
else
{
buttonGroup.Height = barHeight;
}
}
PnlBottomLine.Top = PnlBackGround.Height - (NavButtonGroup.Count - CurrentGroupIndex - 1) * barHeight - 1;
}
/// <summary>
/// 导航条大小发生变更时,重新设置导航条的布局。
/// </summary>
private void NavBar_SizeChanged(object sender, EventArgs e)
{
ResetNavBar();
}
/// <summary>
/// 当前导航栏中选中的导航条编号
/// </summary>
private int CurrentGroupIndex = 0;
/// <summary>
/// 导航栏中的导航条单击事件处理
/// </summary>
private void TitleBar_Click(object sender, EventArgs e)
{
if (sender is ButtonGroup)
{
ButtonGroup buttonGroup = (ButtonGroup)sender;
if (buttonGroup.Text == "退出系统")
{
if (QuitSystemClick != null)
{
QuitSystemClick(buttonGroup, e);
}
return;
}
CurrentGroupIndex = (int)buttonGroup.Tag;
ResetNavBar();
}
}
/// <summary>
/// 导航栏中的图片按钮单击事件处理
/// </summary>
private void ImageButton_Click(object sender, string targetModule)
{
if (ImageButtonClick != null)
{
ImageButtonClick(sender, targetModule);
}
}
#endregion
#region 导航栏类中所定义使用的对象
/// <summary>
/// 导航栏中的导航条
/// </summary>
public class ButtonGroup : UserControl
{
public event EventHandler TitleBarClick;
public event ButtonClickHander ImageButtonClick;
public ButtonGroup(string text)
{
Text = text;
InitializeControl();
}
/// <summary>
/// 初始化导航条
/// </summary>
private void InitializeControl()
{
//
// 导航条上的标题栏
//
TitleBar.Cursor = Cursors.Hand;
TitleBar.TextAlign = ContentAlignment.MiddleCenter;
TitleBar.ForeColor = Color.FromArgb(102, 102, 102);
TitleBar.Location = new Point(0, 0);
TitleBar.Size = new Size(153, 22);
TitleBar.BackgroundImage = Resources.NavBarBG01;
TitleBar.MouseMove += new MouseEventHandler(TitleBar_MouseMove);
TitleBar.MouseLeave += new EventHandler(TitleBar_MouseLeave);
TitleBar.Click += new EventHandler(TitleBar_Click);
//
//ButtonGroup导航条
//
Width = 153;
Height = 22;
this.Controls.Add(TitleBar);
this.Controls.Add(ButtonArea);
}
/// <summary>
/// 初始化导航条所包含或关联的图片按钮
/// </summary>
public void InitImageButtons()
{
int imageButtonHeight = 70;
//
// 导航条上的按钮区域(Panel)
//
ButtonArea.Location = new Point(0, 22);
ButtonArea.Size = new Size(153, imageButtonHeight * ImageButtons.Count);
//
// 导航条上的图片按钮
//
for (int n = 0; n < ImageButtons.Count; n++)
{
ImageButton imageButton = ImageButtons[n];
imageButton.Left = 0;
imageButton.Top = n * imageButtonHeight;
imageButton.ImageButtonClick += new ButtonClickHander(ImageButton_Click);
ButtonArea.Controls.Add(imageButton);
}
}
private System.Windows.Forms.Label TitleBar = new System.Windows.Forms.Label();
private Panel ButtonArea = new Panel();
... ...
补充:.NET技术 , C#