你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / Linux开发
Visual C# .Net环境中编程实现浮动工具栏(2)
 

if ((currentPt.X > minpt.X) && (currentPt.X < maxpt.X) && (currentPt.Y > minpt.Y) && (currentPt.Y < maxpt.Y))
...{
this.floatWindow.Controls.Remove(this);
this.tsPanel.SuspendLayout();
this.tsPanel.Controls.Add(this);
this.Location = this.tsPanel.PointToClient(currentPt);
this.tsPanel.ResumeLayout();
this.floatWindow.Dispose();
this.floatWindow = null;

}
}

private void MyToolStrip_EndDrag(object sender, EventArgs e)
...{
//判断移出时
if (this.tsPanel == null)
...{
MessageBox.Show("请先设置ToolStripPanel属性");
return;
}
Point endPoint = Cursor.Position;
int openX, openY;
openX = endPoint.X;
openY = endPoint.Y;
Point clientPt = this.tsPanel.Parent.PointToClient(endPoint);
if (clientPt.Y > tsPanel.Height)
...{
ToolStripFloatWindow fw = new ToolStripFloatWindow();
this.tsPanel.Controls.Remove(this);
fw.Controls.Add(this);
this.Left = 0;
this.Top = 0;
this.FloatWindow = fw;
Point newLoc = new Point(openX, openY);
fw.Show();
fw.Location = newLoc;
fw.SetBounds(newLoc.X, newLoc.Y, this.ClientSize.Width, this.ClientSize.Height);
}
}

private void floatWindow_FormClosing(object sender, FormClosingEventArgs e)
...{
e.Cancel = true;
}

private void MyToolStrip_SizeChanged(object sender, EventArgs e)
...{
if (this.isFloating)
...{
this.floatWindow.Width = this.ClientSize.Width;
}
}

#endregion

}
}

结论。 该方法实现较简单, 当不愿意使用功能较强大的第三方控件库时可以采用这种方法,缺点是负责浮动的容器是一个窗口,不大美观。

(编辑:aniston)

  推荐精品文章

·2024年12月目录 
·2024年11月目录 
·2024年10月目录 
·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089