解决frmMain窗体的Dock组件根据NavBarControl自动同步缩放
解决frmMain窗体的Dock组件根据NavBarControl自动同步缩放
扫一扫加微信
接上文:关于NavBarControl点击ExpandButton缩放后不能控制Dock组件的问题
解决方案2:不隐藏ShowExpandButton实现NavBarControl自动缩放。
打开frmMain.cs文件,添加以下代码:
C# Code:
//NavBarControl尺寸改变时的标记
private bool _OnSizeChangingNavBar = false;
private void navBarControl1_SizeChanged(object sender, EventArgs e)
{
if (_OnSizeChangingNavBar) return;
if (_OnSizeChangingDock) return;
try
{
_OnSizeChangingNavBar = true;
if (dockPanel1.Visibility == DockVisibility.Visible && navBarControl1.Visible && navBarControl1.Width > 0)
{
dockPanel1.Width = navBarControl1.Width;
}
}
finally
{
_OnSizeChangingNavBar = false;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
private bool _OnSizeChangingNavBar = false;
private void navBarControl1_SizeChanged(object sender, EventArgs e)
{
if (_OnSizeChangingNavBar) return;
if (_OnSizeChangingDock) return;
try
{
_OnSizeChangingNavBar = true;
if (dockPanel1.Visibility == DockVisibility.Visible && navBarControl1.Visible && navBarControl1.Width > 0)
{
dockPanel1.Width = navBarControl1.Width;
}
}
finally
{
_OnSizeChangingNavBar = false;
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
修改原有dockPanel1_SizeChanged事件的代码:
C# Code:
//Doc组件尺寸改变时的标记
private bool _OnSizeChangingDock = false;
//frmMain.dockPanel1_SizeChanged
private void dockPanel1_SizeChanged(object sender, EventArgs e)
{
if (_OnSizeChangingDock) return;
try
{
this.SuspendLayout();
_OnSizeChangingDock = true;
navBarControl1.Dock = DockStyle.None;
navBarControl1.Left = xtraScrollableControl1.DisplayRectangle.X;//滚动容器的实际坐标
navBarControl1.Top = xtraScrollableControl1.DisplayRectangle.Y;//滚动容器的实际坐标
navBarControl1.NavigationPaneGroupClientHeight = 100;//导航按钮展开显示明细菜单区域的高度。
navBarControl1.Height = navBarControl1.Groups.Count * 70 + navBarControl1.NavigationPaneGroupClientHeight;//手工指定NavBar组件的高度
navBarControl1.OptionsNavPane.ShowOverflowButton = false;//不显示底部的动态扩展按钮
navBarControl1.OptionsNavPane.ShowOverflowPanel = false;//不显示底部的动态扩展按钮区域
xtraScrollableControl1.HorizontalScroll.Visible = false;//不显示横向滚动条
//若NavBar显示垂直滚动条,要预留明细区域的滚动条,约25个像素
if (xtraScrollableControl1.VerticalScroll.Visible)
navBarControl1.Width = dockPanel1.Width - 25;//右侧预留边距
else
navBarControl1.Width = dockPanel1.Width - 5;//右侧预留边距
//NavBar全屏自适应高度
if (dockPanel1.ClientSize.Height - 60 > navBarControl1.Height)
navBarControl1.Height = dockPanel1.ClientSize.Height - 60;
}
finally
{
_OnSizeChangingDock = false;
this.ResumeLayout();
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
//Doc组件尺寸改变时的标记
private bool _OnSizeChangingDock = false;
//frmMain.dockPanel1_SizeChanged
private void dockPanel1_SizeChanged(object sender, EventArgs e)
{
if (_OnSizeChangingDock) return;
try
{
this.SuspendLayout();
_OnSizeChangingDock = true;
navBarControl1.Dock = DockStyle.None;
navBarControl1.Left = xtraScrollableControl1.DisplayRectangle.X;//滚动容器的实际坐标
navBarControl1.Top = xtraScrollableControl1.DisplayRectangle.Y;//滚动容器的实际坐标
navBarControl1.NavigationPaneGroupClientHeight = 100;//导航按钮展开显示明细菜单区域的高度。
navBarControl1.Height = navBarControl1.Groups.Count * 70 + navBarControl1.NavigationPaneGroupClientHeight;//手工指定NavBar组件的高度
navBarControl1.OptionsNavPane.ShowOverflowButton = false;//不显示底部的动态扩展按钮
navBarControl1.OptionsNavPane.ShowOverflowPanel = false;//不显示底部的动态扩展按钮区域
xtraScrollableControl1.HorizontalScroll.Visible = false;//不显示横向滚动条
//若NavBar显示垂直滚动条,要预留明细区域的滚动条,约25个像素
if (xtraScrollableControl1.VerticalScroll.Visible)
navBarControl1.Width = dockPanel1.Width - 25;//右侧预留边距
else
navBarControl1.Width = dockPanel1.Width - 5;//右侧预留边距
//NavBar全屏自适应高度
if (dockPanel1.ClientSize.Height - 60 > navBarControl1.Height)
navBarControl1.Height = dockPanel1.ClientSize.Height - 60;
}
finally
{
_OnSizeChangingDock = false;
this.ResumeLayout();
}
}
//来源:C/S框架网 | www.csframework.com | QQ:23404761
扫一扫加微信
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网