■ XtraTabbedMdiManager 클래스에서 드래그시 선택 페이지를 변경하는 방법을 보여준다.
▶ DragHelper.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
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 } } |
▶ ChildForm1.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
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 } } |
▶ ChildForm2.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
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 } } |