| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:DockPanel.cs
- * 2.功能描述:类文件
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/01 1.00 新建
- *******************************************************************************/
- using System.Drawing;
- using System.Windows.Forms;
- namespace Dongke.IBOSS.PRD.Basics.DockPanel
- {
- /// <summary>
- /// 类文件
- /// </summary>
- partial class DockPanel
- {
- private sealed class SplitterDragHandler : DragHandler
- {
- private class SplitterOutline
- {
- public SplitterOutline()
- {
- m_dragForm = new DragForm();
- SetDragForm(Rectangle.Empty);
- DragForm.BackColor = Color.Black;
- DragForm.Opacity = 0.7;
- DragForm.Show(false);
- }
- DragForm m_dragForm;
- private DragForm DragForm
- {
- get
- {
- return m_dragForm;
- }
- }
- public void Show(Rectangle rect)
- {
- SetDragForm(rect);
- }
- public void Close()
- {
- DragForm.Close();
- }
- private void SetDragForm(Rectangle rect)
- {
- DragForm.Bounds = rect;
- if (rect == Rectangle.Empty)
- DragForm.Region = new Region(Rectangle.Empty);
- else if (DragForm.Region != null)
- DragForm.Region = null;
- }
- }
- public SplitterDragHandler(DockPanel dockPanel)
- : base(dockPanel)
- {
- }
- public new ISplitterDragSource DragSource
- {
- get
- {
- return base.DragSource as ISplitterDragSource;
- }
- private set
- {
- base.DragSource = value;
- }
- }
- private SplitterOutline m_outline;
- private SplitterOutline Outline
- {
- get
- {
- return m_outline;
- }
- set
- {
- m_outline = value;
- }
- }
- private Rectangle m_rectSplitter;
- private Rectangle RectSplitter
- {
- get
- {
- return m_rectSplitter;
- }
- set
- {
- m_rectSplitter = value;
- }
- }
- public void BeginDrag(ISplitterDragSource dragSource, Rectangle rectSplitter)
- {
- DragSource = dragSource;
- RectSplitter = rectSplitter;
- if (!BeginDrag())
- {
- DragSource = null;
- return;
- }
- Outline = new SplitterOutline();
- Outline.Show(rectSplitter);
- DragSource.BeginDrag(rectSplitter);
- }
- protected override void OnDragging()
- {
- Outline.Show(GetSplitterOutlineBounds(Control.MousePosition));
- }
- protected override void OnEndDrag(bool abort)
- {
- DockPanel.SuspendLayout(true);
- Outline.Close();
- if (!abort)
- DragSource.MoveSplitter(GetMovingOffset(Control.MousePosition));
- DragSource.EndDrag();
- DockPanel.ResumeLayout(true, true);
- }
- private int GetMovingOffset(Point ptMouse)
- {
- Rectangle rect = GetSplitterOutlineBounds(ptMouse);
- if (DragSource.IsVertical)
- return rect.X - RectSplitter.X;
- else
- return rect.Y - RectSplitter.Y;
- }
- private Rectangle GetSplitterOutlineBounds(Point ptMouse)
- {
- Rectangle rectLimit = DragSource.DragLimitBounds;
- Rectangle rect = RectSplitter;
- if (rectLimit.Width <= 0 || rectLimit.Height <= 0)
- return rect;
- if (DragSource.IsVertical)
- {
- rect.X += ptMouse.X - StartMousePosition.X;
- rect.Height = rectLimit.Height;
- }
- else
- {
- rect.Y += ptMouse.Y - StartMousePosition.Y;
- rect.Width = rectLimit.Width;
- }
- if (rect.Left < rectLimit.Left)
- rect.X = rectLimit.X;
- if (rect.Top < rectLimit.Top)
- rect.Y = rectLimit.Y;
- if (rect.Right > rectLimit.Right)
- rect.X -= rect.Right - rectLimit.Right;
- if (rect.Bottom > rectLimit.Bottom)
- rect.Y -= rect.Bottom - rectLimit.Bottom;
- return rect;
- }
- }
- private SplitterDragHandler m_splitterDragHandler = null;
- private SplitterDragHandler GetSplitterDragHandler()
- {
- if (m_splitterDragHandler == null)
- m_splitterDragHandler = new SplitterDragHandler(this);
- return m_splitterDragHandler;
- }
- internal void BeginDrag(ISplitterDragSource dragSource, Rectangle rectSplitter)
- {
- GetSplitterDragHandler().BeginDrag(dragSource, rectSplitter);
- }
- }
- }
|