关于浮动工具条的制作,阿捷写了一篇很不错的文章,见:http://www.weikejianghu.com/article/44272.htm
阿捷这个工具条浮动后只能在顶部停靠,基于此,我在这边增加在左/右/底部停靠,停靠条件是浮动窗体紧贴或越过主窗体边缘。
其实阿捷给出的代码已经相当详细了:) 我这里主要给出重写的ToolStrip代码段,增加了三个ToolStripPanel
#region 漂浮状态
public ToolStripFloatWindow FloatWindow { get; set; }
private bool isFloating
{
get
{
return (FloatWindow != null);
}
}
public ToolStripPanel TopToolStripPanel { get; set; }
public ToolStripPanel BottomToolStripPanel { get; set; }
public ToolStripPanel LeftToolStripPanel { get; set; }
public ToolStripPanel RightToolStripPanel { get; set; }
#endregion
#region 漂浮实现
private void FloatWindow_LocationChanged(object sender, EventArgs e)
{
//当floatwindws的位置移动到 toolstrippanel中时,将this放置到 toolstripPanel上
if (this.FloatWindow == null)
{
return;
}
if (FloatWindow.HasCreated)
{
//主窗体位置
Point frmLoc = this.TopToolStripPanel.Parent.Location;
//浮动工具条位置
Point toolBarLoc = FloatWindow.Location;
if (toolBarLoc.Y - frmLoc.Y <= 0) //置于顶部StripPanel
{
this.FloatWindow.Controls.Remove(this);
this.TopToolStripPanel.SuspendLayout();
this.TopToolStripPanel.Controls.Add(this);
this.Location = this.TopToolStripPanel.PointToClient(toolBarLoc);
this.TopToolStripPanel.ResumeLayout();
this.FloatWindow.Dispose();
this.FloatWindow = null;
return;
}
if (toolBarLoc.X - frmLoc.X <= 0) //置于左边StripPanel
{
this.FloatWindow.Controls.Remove(this);
this.LeftToolStripPanel.SuspendLayout();
this.LeftToolStripPanel.Controls.Add(this);
this.Location = this.LeftToolStripPanel.PointToClient(toolBarLoc);
this.LeftToolStripPanel.ResumeLayout();
this.FloatWindow.Dispose();
this.FloatWindow = null;
return;
}
if (toolBarLoc.X + FloatWindow.Width >= this.TopToolStripPanel.Parent.Width) //置于右边StripPanel
{
this.FloatWindow.Controls.Remove(this);
this.RightToolStripPanel.SuspendLayout();
this.RightToolStripPanel.Controls.Add(this);
this.Location = this.RightToolStripPanel.PointToClient(toolBarLoc);
&nb