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)
|