总结
总结: 处理好bar之间的布局 ,
有3个需要注意的点 [ 设置DockSide的顺序(想象一下俄罗斯方块落下的顺序) , DockLine , Stretch , DockOffset ]
当然其它属性也很重要 , 但是粗略的布局 , 先需要注意这几点
#tucao
"DevComponents.DotNetBar"是有点难用啊 , 并且网上相关教程也很少 , , ,
直接上代码
using DevComponents.DotNetBar;
using System.Windows.Forms;
namespace WindowsFormsApp2
{
public partial class DockSiteBarManagerSample : Form
{
private DevComponents.DotNetBar.DotNetBarManager dotNetBarManager1;
private DevComponents.DotNetBar.DockSite dockSite4;
private DevComponents.DotNetBar.DockSite dockSite1;
private DevComponents.DotNetBar.DockSite dockSite2;
private DevComponents.DotNetBar.DockSite dockSite3;
private Bar bar1, bar2, bar3, bar4, bar5, bar6, bar7, bar8, bar9, bar10, bar11, bar12, bar13, bar14, bar15;
public DockSiteBarManagerSample()
{
InitializeComponent();
this.components = new System.ComponentModel.Container();
this.dotNetBarManager1 = new DevComponents.DotNetBar.DotNetBarManager(this.components);
this.dockSite4 = new DevComponents.DotNetBar.DockSite();
this.dockSite1 = new DevComponents.DotNetBar.DockSite();
this.dockSite2 = new DevComponents.DotNetBar.DockSite();
this.dockSite3 = new DevComponents.DotNetBar.DockSite();
//
// dotNetBarManager1
//
this.dotNetBarManager1.BottomDockSite = null;
this.dotNetBarManager1.LeftDockSite = null;
this.dotNetBarManager1.ParentForm = this;
this.dotNetBarManager1.RightDockSite = null;
this.dotNetBarManager1.ShowCustomizeContextMenu = false;
this.dotNetBarManager1.UseGlobalColorScheme = false;
this.dotNetBarManager1.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
this.dotNetBarManager1.ToolbarBottomDockSite = this.dockSite4;
this.dotNetBarManager1.ToolbarLeftDockSite = this.dockSite1;
this.dotNetBarManager1.ToolbarRightDockSite = this.dockSite2;
this.dotNetBarManager1.ToolbarTopDockSite = this.dockSite3;
this.dotNetBarManager1.TopDockSite = null;
//
// dockSite4
//
this.dockSite4.AccessibleRole = System.Windows.Forms.AccessibleRole.Window;
this.dockSite4.Dock = System.Windows.Forms.DockStyle.Bottom;
this.dockSite4.Location = new System.Drawing.Point(0, 453);
this.dockSite4.Name = "dockSite4";
this.dockSite4.Size = new System.Drawing.Size(782, 0);
this.dockSite4.TabIndex = 3;
this.dockSite4.TabStop = false;
this.dockSite4.Visible = true;
//
// dockSite1
//
this.dockSite1.AccessibleRole = System.Windows.Forms.AccessibleRole.Window;
this.dockSite1.Dock = System.Windows.Forms.DockStyle.Left;
this.dockSite1.Location = new System.Drawing.Point(0, 0);
this.dockSite1.Name = "dockSite1";
this.dockSite1.Size = new System.Drawing.Size(0, 453);
this.dockSite1.TabIndex = 0;
this.dockSite1.TabStop = false;
this.dockSite1.Visible = true;
//
// dockSite2
//
this.dockSite2.AccessibleRole = System.Windows.Forms.AccessibleRole.Window;
this.dockSite2.Dock = System.Windows.Forms.DockStyle.Right;
this.dockSite2.Location = new System.Drawing.Point(782, 0);
this.dockSite2.Name = "dockSite2";
this.dockSite2.Size = new System.Drawing.Size(0, 453);
this.dockSite2.TabIndex = 1;
this.dockSite2.TabStop = false;
this.dockSite2.Visible = true;
//
// dockSite3
//
this.dockSite3.AccessibleRole = System.Windows.Forms.AccessibleRole.Window;
this.dockSite3.Dock = System.Windows.Forms.DockStyle.Top;
this.dockSite3.Location = new System.Drawing.Point(0, 0);
this.dockSite3.Name = "dockSite3";
this.dockSite3.Size = new System.Drawing.Size(782, 0);
this.dockSite3.TabIndex = 2;
this.dockSite3.TabStop = false;
this.dockSite3.BackColor = System.Drawing.Color.Red;
this.Controls.Add(this.dockSite1);
this.Controls.Add(this.dockSite2);
this.Controls.Add(this.dockSite3);
this.Controls.Add(this.dockSite4);
BarsTest();
}
private void BarsTest()
{
bar1 = InitializeBar("bar1", eDockSide.Top);
bar2 = InitializeBar("bar2", eDockSide.Top);
bar3 = InitializeBar("bar3", eDockSide.Top);
//bar4 = InitializeBar("bar4", eDockSide.Top);
//bar5 = InitializeBar("bar5", eDockSide.Bottom);
//bar6 = InitializeBar("bar6", eDockSide.Bottom);
//bar7 = InitializeBar("bar7", eDockSide.Left);
//bar8 = InitializeBar("bar8", eDockSide.Right);
//bar1独占1行, bar2和bar3占1行,
bar1.Stretch = true;
bar1.DockLine = 3;
bar2.Stretch = false;
bar3.Stretch = false;
bar2.DockLine = 0;
bar3.DockLine = 0;
dotNetBarManager1.Bars.Add(bar3);
dotNetBarManager1.Bars.Add(bar1);
dotNetBarManager1.Bars.Add(bar2);
//dotNetBarManager1.Bars.Add(bar4);
//dotNetBarManager1.Bars.Add(bar5);
//dotNetBarManager1.Bars.Add(bar6);
//dotNetBarManager1.Bars.Add(bar7);
//dotNetBarManager1.Bars.Add(bar8);
//添加顺序直接关系到谁在第一个谁在第二个...
bar2.DockSide = eDockSide.Top;
bar3.DockSide = eDockSide.Top;
bar1.DockSide = eDockSide.Top;
//总结: 处理好bar之间的布局 ,
//有3个需要注意的点 [ 设置DockSide的顺序(想象一下俄罗斯方块落下的顺序) , DockLine , Stretch , DockOffset ]
//当然其它属性也很重要 , 但是粗略的布局 , 先需要注意这几点
bar1.LayoutType = DevComponents.DotNetBar.eLayoutType.Toolbar;
bar2.LayoutType = DevComponents.DotNetBar.eLayoutType.Toolbar;
bar3.LayoutType = DevComponents.DotNetBar.eLayoutType.Toolbar;
//bar4.DockSide = eDockSide.Top;
//bar4.LayoutType = DevComponents.DotNetBar.eLayoutType.DockContainer;
//bar5.DockSide = eDockSide.Bottom;
//bar6.DockSide = eDockSide.Left;
//bar7.DockSide = eDockSide.Left;
//bar8.DockSide = eDockSide.Right;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="bar"></param>
/// <param name="name"></param>
private Bar InitializeBar(string name, eDockSide eDockSide)
{
Bar bar = new Bar();
bar.Text = name;
bar.Name = name;
bar.AlwaysDisplayDockTab = true;//Indicates whether tab that shows all dock containers on the bar is visible all the time.
bar.CanCustomize = false;
bar.CanDockBottom = true;
bar.CanDockDocument = true;
bar.CanDockLeft = true;
bar.CanDockRight = true;
bar.CanDockTop = true;
bar.CanHide = true;
bar.CanUndock = true;
bar.ShowToolTips = true;
//bar.IsHandleDoubleClickExternal = true;
//Stretch
bar.Stretch = false;//Specifies whether Bar will stretch to always fill the space in dock site.
bar.TabNavigation = true;
bar.TabStop = true;
bar.AccessibleRole = System.Windows.Forms.AccessibleRole.ToolBar;
//要想无限加bar就不能设置最小值,否则bar加多了显示会有问题
//bar.MinimumSize = new Size(300, 200);
//bar.DockTabAlignment = DevComponents.DotNetBar.eTabStripAlignment.Top;//Gets or sets the dock tab alignment.
//bar.LayoutType = DevComponents.DotNetBar.eLayoutType.DockContainer;
bar.Style = eDotNetBarStyle.Office2007;
bar.DockLine = 0;
bar.DockOffset = 10;
BarAddButtonTest(bar);
bar.DockSide = eDockSide;
return bar;
}
/// <summary>
/// 向Bar中添加测试Items
/// </summary>
/// <param name="bar"></param>
private void BarAddButtonTest(Bar bar)
{
var _fileToolStripMenuItem = new ButtonItem();
_fileToolStripMenuItem.Name = "fileToolStripMenuItem";
_fileToolStripMenuItem.Size = new System.Drawing.Size(180, 180);
_fileToolStripMenuItem.CanCustomize = true;
_fileToolStripMenuItem.UserCustomized = true;
//_fileToolStripMenuItem.FixedSize = new System.Drawing.Size(180, 180);
_fileToolStripMenuItem.FontBold = true;
_fileToolStripMenuItem.FontItalic = true;
_fileToolStripMenuItem.FontUnderline = true;
_fileToolStripMenuItem.HotFontBold = true;
_fileToolStripMenuItem.HotFontUnderline = true;
_fileToolStripMenuItem.Category = "Standard";
_fileToolStripMenuItem.AccessibleRole = System.Windows.Forms.AccessibleRole.MenuItem;
_fileToolStripMenuItem.Text = "Test1111";
var test = new ButtonItem();
test.Text = "测试111";
test.Click += (sender, e) =>
{
MessageBox.Show("Test--click");
};
_fileToolStripMenuItem.SubItems.Add(test);
bar.Items.AddRange
(
new BaseItem[]
{
new ButtonItem { Text = "Button"+ bar.Name },
new TextBoxItem { Text = "TextBox"+ bar.Name },
new ButtonItem { Text = "Button"+ bar.Name },
_fileToolStripMenuItem,
}
);
}
}
}