C# ToolStrip制作四邊??扛庸ぞ邫?/h1>
更新時間:2013年12月09日 11:57:50 作者:
這篇文章主要介紹了C# ToolStrip浮動工具欄的制作,可以上/下/左/右???,代碼在下面
關(guān)于浮動工具條的制作,阿捷寫了一篇很不錯的文章,見:http://www.dbjr.com.cn/article/44272.htm
阿捷這個工具條浮動后只能在頂部??浚诖?,我在這邊增加在左/右/底部???,停靠條件是浮動窗體緊貼或越過主窗體邊緣。
其實阿捷給出的代碼已經(jīng)相當(dāng)詳細了:) 我這里主要給出重寫的ToolStrip代碼段,增加了三個ToolStripPanel
復(fù)制代碼 代碼如下:
public partial class MyToolStrip : ToolStrip
{
public MyToolStrip()
{
InitializeComponent();
this.EndDrag += new EventHandler(MyToolStrip_EndDrag);
this.SizeChanged += new EventHandler(MyToolStrip_SizeChanged);
}
#region 漂浮狀態(tài)
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 漂浮實現(xiàn)
private void FloatWindow_LocationChanged(object sender, EventArgs e)
{
//當(dāng)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);
this.RightToolStripPanel.ResumeLayout();
this.FloatWindow.Dispose();
this.FloatWindow = null;
return;
}
if (toolBarLoc.Y + FloatWindow.Height >= this.TopToolStripPanel.Parent.Height) //置于底部StripPanel
{
this.FloatWindow.Controls.Remove(this);
this.BottomToolStripPanel.SuspendLayout();
this.BottomToolStripPanel.Controls.Add(this);
this.Location = this.BottomToolStripPanel.PointToClient(toolBarLoc);
this.BottomToolStripPanel.ResumeLayout();
this.FloatWindow.Dispose();
this.FloatWindow = null;
return;
}
}
}
private void MyToolStrip_EndDrag(object sender, EventArgs e)
{
Point screenPt = Cursor.Position;
Point clientPt = this.TopToolStripPanel.Parent.PointToClient(screenPt);
//浮動區(qū)域
Rectangle floatArea = new Rectangle(32, 32, //我這里圖標大小調(diào)整為32*32
this.TopToolStripPanel.Parent.Width - 2 * 32,
this.TopToolStripPanel.Parent.Height - 2 * 32);
if (floatArea.Contains(clientPt)) //判斷移出時
{
ToolStripFloatWindow fw = new ToolStripFloatWindow();
fw.Controls.Add(this);
this.Left = 0;
this.Top = 0;
this.FloatWindow = fw;
FloatWindow.LocationChanged += new EventHandler(FloatWindow_LocationChanged);
fw.SetBounds(screenPt.X, screenPt.Y, this.ClientSize.Width, this.ClientSize.Height + 22); //22為窗體標題欄高度
fw.Show();
}
}
private void MyToolStrip_SizeChanged(object sender, EventArgs e)
{
if (this.isFloating)
{
this.FloatWindow.Width = this.ClientSize.Width;
}
}
#endregion
}
相關(guān)文章
-
C#實現(xiàn)把圖片轉(zhuǎn)換成二進制以及把二進制轉(zhuǎn)換成圖片的方法示例
這篇文章主要介紹了C#實現(xiàn)把圖片轉(zhuǎn)換成二進制以及把二進制轉(zhuǎn)換成圖片的方法,結(jié)合具體實例形式分析了基于C#的圖片與二進制相互轉(zhuǎn)換以及圖片保存到數(shù)據(jù)庫的相關(guān)操作技巧,需要的朋友可以參考下 2017-06-06
-
DevExpress SplitContainerControl用法總結(jié)
這篇文章主要介紹了DevExpress SplitContainerControl用法,對初學(xué)者有一定的參考借鑒價值,需要的朋友可以參考下 2014-08-08
最新評論
關(guān)于浮動工具條的制作,阿捷寫了一篇很不錯的文章,見:http://www.dbjr.com.cn/article/44272.htm
阿捷這個工具條浮動后只能在頂部??浚诖?,我在這邊增加在左/右/底部???,停靠條件是浮動窗體緊貼或越過主窗體邊緣。
其實阿捷給出的代碼已經(jīng)相當(dāng)詳細了:) 我這里主要給出重寫的ToolStrip代碼段,增加了三個ToolStripPanel
public partial class MyToolStrip : ToolStrip
{
public MyToolStrip()
{
InitializeComponent();
this.EndDrag += new EventHandler(MyToolStrip_EndDrag);
this.SizeChanged += new EventHandler(MyToolStrip_SizeChanged);
}
#region 漂浮狀態(tài)
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 漂浮實現(xiàn)
private void FloatWindow_LocationChanged(object sender, EventArgs e)
{
//當(dāng)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);
this.RightToolStripPanel.ResumeLayout();
this.FloatWindow.Dispose();
this.FloatWindow = null;
return;
}
if (toolBarLoc.Y + FloatWindow.Height >= this.TopToolStripPanel.Parent.Height) //置于底部StripPanel
{
this.FloatWindow.Controls.Remove(this);
this.BottomToolStripPanel.SuspendLayout();
this.BottomToolStripPanel.Controls.Add(this);
this.Location = this.BottomToolStripPanel.PointToClient(toolBarLoc);
this.BottomToolStripPanel.ResumeLayout();
this.FloatWindow.Dispose();
this.FloatWindow = null;
return;
}
}
}
private void MyToolStrip_EndDrag(object sender, EventArgs e)
{
Point screenPt = Cursor.Position;
Point clientPt = this.TopToolStripPanel.Parent.PointToClient(screenPt);
//浮動區(qū)域
Rectangle floatArea = new Rectangle(32, 32, //我這里圖標大小調(diào)整為32*32
this.TopToolStripPanel.Parent.Width - 2 * 32,
this.TopToolStripPanel.Parent.Height - 2 * 32);
if (floatArea.Contains(clientPt)) //判斷移出時
{
ToolStripFloatWindow fw = new ToolStripFloatWindow();
fw.Controls.Add(this);
this.Left = 0;
this.Top = 0;
this.FloatWindow = fw;
FloatWindow.LocationChanged += new EventHandler(FloatWindow_LocationChanged);
fw.SetBounds(screenPt.X, screenPt.Y, this.ClientSize.Width, this.ClientSize.Height + 22); //22為窗體標題欄高度
fw.Show();
}
}
private void MyToolStrip_SizeChanged(object sender, EventArgs e)
{
if (this.isFloating)
{
this.FloatWindow.Width = this.ClientSize.Width;
}
}
#endregion
}
相關(guān)文章
C#實現(xiàn)把圖片轉(zhuǎn)換成二進制以及把二進制轉(zhuǎn)換成圖片的方法示例
這篇文章主要介紹了C#實現(xiàn)把圖片轉(zhuǎn)換成二進制以及把二進制轉(zhuǎn)換成圖片的方法,結(jié)合具體實例形式分析了基于C#的圖片與二進制相互轉(zhuǎn)換以及圖片保存到數(shù)據(jù)庫的相關(guān)操作技巧,需要的朋友可以參考下2017-06-06DevExpress SplitContainerControl用法總結(jié)
這篇文章主要介紹了DevExpress SplitContainerControl用法,對初學(xué)者有一定的參考借鑒價值,需要的朋友可以參考下2014-08-08