첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

TestProject.zip
다운로드

▶ DragHelper.cs

using System.Drawing;
using System.Windows.Forms;

using DevExpress.Utils.Mdi;
using DevExpress.XtraTab;
using DevExpress.XtraTab.ViewInfo;
using DevExpress.XtraTabbedMdi;

namespace TestProject
{
    /// <summary>
    /// 드래그 헬퍼
    /// </summary>
    public class DragHelper
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// XTRA 탭 MDI 관리자
        /// </summary>
        private XtraTabbedMdiManager manager;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 드래그시 새 페이지 선택 여부 - SelectNewPageOnDrag

        /// <summary>
        /// 드래그시 새 페이지 선택 여부
        /// </summary>
        public bool SelectNewPageOnDrag
        {
            set
            {
                MDIClient.DragOver -= MDIClient_DragOver;

                if(value)
                {
                    MDIClient.DragOver += MDIClient_DragOver;
                }
            }
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region MDI 클라이언트 - MDIClient

        /// <summary>
        /// MDI 클라이언트
        /// </summary>
        private MdiClient MDIClient
        {
            get
            {
                return MdiClientSubclasser.GetMdiClient(this.manager.MdiParent);
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - DragHelper(manager)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="manager">XTRA 탭 MDI 관리자</param>
        public DragHelper(XtraTabbedMdiManager manager)
        {
            this.manager = manager;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region MDI 클라이언트 드래그 OVER 처리하기 - MDIClient_DragOver(sender, e)

        /// <summary>
        /// MDI 클라이언트 드래그 OVER 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        protected void MDIClient_DragOver(object sender, DragEventArgs e)
        {
            IXtraTab xtraTab = this.manager as IXtraTab;

            Point mousePoint = xtraTab.ScreenPointToControl(new Point(e.X, e.Y));

            BaseTabHitInfo hitInfo = this.manager.CalcHitInfo(mousePoint);

            if(hitInfo.HitTest == XtraTabHitTest.PageHeader)
            {
                this.manager.SelectedPage = (XtraMdiTabPage)hitInfo.Page;
            }
        }

        #endregion
    }
}

 

728x90

 

▶ ChildForm1.cs

using System;
using System.Drawing;
using System.Windows.Forms;

using DevExpress.XtraEditors;

namespace TestProject
{
    /// <summary>
    /// 자식 폼 1
    /// </summary>
    public partial class ChildForm1 : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 시작 포인트
        /// </summary>
        private Point startPoint;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - ChildForm1()

        /// <summary>
        /// 생성자
        /// </summary>
        public ChildForm1()
        {
            InitializeComponent();

            this.listBoxControl.MouseDown += listBoxControl_MouseDown;
            this.listBoxControl.MouseMove += listBoxControl_MouseMove;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 리스트 박스 컨트롤 마우스 DOWN 처리하기 - listBoxControl_MouseDown(sender, e)

        /// <summary>
        /// 리스트 박스 컨트롤 마우스 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void listBoxControl_MouseDown(object sender, MouseEventArgs e)
        {
            ListBoxControl listBoxControl = sender as ListBoxControl;

            this.startPoint = new Point(e.X, e.Y);

            int selectedIndex = listBoxControl.IndexFromPoint(startPoint);

            if(selectedIndex == -1)
            {
                this.startPoint = Point.Empty;
            }
        }

        #endregion
        #region 리스트 박스 컨트롤 마우스 이동시 처리하기 - listBoxControl_MouseMove(sender, e)

        /// <summary>
        /// 리스트 박스 컨트롤 마우스 이동시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void listBoxControl_MouseMove(object sender, MouseEventArgs e)
        {
            ListBoxControl listBoxControl = sender as ListBoxControl;

            if(e.Button == MouseButtons.Left)
            {
                if
                (
                    (startPoint != Point.Empty) &&
                    (
                        (Math.Abs(e.X - startPoint.X) > SystemInformation.DragSize.Width ) ||
                        (Math.Abs(e.Y - startPoint.Y) > SystemInformation.DragSize.Height)
                    )
                )
                {
                    listBoxControl.DoDragDrop(listBoxControl.SelectedItem, DragDropEffects.Copy);
                }
            }
        }

        #endregion
    }
}

 

300x250

 

▶ ChildForm2.cs

using System.Windows.Forms;

using DevExpress.XtraEditors;

namespace TestProject
{
    /// <summary>
    /// 자식 폼 2
    /// </summary>
    public partial class ChildForm2 : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - ChildForm2()

        /// <summary>
        /// 생성자
        /// </summary>
        public ChildForm2()
        {
            InitializeComponent();

            this.listBoxControl.DragDrop += listBoxControl_DragDrop;
            this.listBoxControl.DragOver += listBoxControl_DragOver;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 리스트 박스 컨트롤 드래그 OVER 처리하기 - listBoxControl_DragOver(sender, e)

        /// <summary>
        /// 리스트 박스 컨트롤 드래그 OVER 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void listBoxControl_DragOver(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
        }

        #endregion
        #region 리스트 박스 컨트롤 드래그 DROP 처리하기 - listBoxControl_DragDrop(sender, e)

        /// <summary>
        /// 리스트 박스 컨트롤 드래그 DROP 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void listBoxControl_DragDrop(object sender, DragEventArgs e)
        {
            if(e.Data.GetDataPresent(typeof(string)))
            {
                string text = (string)e.Data.GetData(typeof(string));

                this.listBoxControl.Items.Add(text);
            }
        }

        #endregion
    }
}

 

▶ MainForm.cs

using System;
using System.Windows.Forms;

using DevExpress.XtraEditors;

namespace TestProject
{
    /// <summary>
    /// 메인 폼
    /// </summary>
    public partial class MainForm : XtraForm
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 드래그 헬퍼
        /// </summary>
        private DragHelper helper;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainForm()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            Load += Form_Load;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Protected

        #region 폼을 닫을 경우 처리하기 - OnFormClosing(e)

        /// <summary>
        /// 폼을 닫을 경우 처리하기
        /// </summary>
        /// <param name="e">이벤트 인자</param>
        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            base.OnFormClosing(e);

            this.helper.SelectNewPageOnDrag = false;
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 폼 로드시 처리하기 - Form_Load(sender, e)

        /// <summary>
        /// 폼 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Form_Load(object sender, EventArgs e)
        {
            ChildForm1 form1 = new ChildForm1();

            form1.MdiParent = this;

            form1.Show();

            ChildForm2 form2 = new ChildForm2();

            form2.MdiParent = this;

            form2.Show();

            form1.BringToFront();

            this.helper = new DragHelper(this.xtraTabbedMdiManager);

            this.helper.SelectNewPageOnDrag = true;
        }

        #endregion
    }
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요