■ DocumentControl 클래스를 사용해 문서 컨트롤을 만드는 방법을 보여준다.
[플로팅 문서]
▶ DocumentOption.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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
using System.Drawing; namespace TestProject { /// <summary> /// 문서 옵션 /// </summary> public class DocumentOption { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 왼쪽 도킹 허용 여부 /// </summary> private bool allowDockLeft = true; /// <summary> /// 위쪽 도킹 허용 여부 /// </summary> private bool allowDockTop = true; /// <summary> /// 오른쪽 도킹 허용 여부 /// </summary> private bool allowDockRight = true; /// <summary> /// 아래쪽 도킹 허용 여부 /// </summary> private bool allowDockBottom = true; /// <summary> /// 채우기 도킹 허용 여부 /// </summary> private bool allowDockFill = true; /// <summary> /// 플로팅 허용 여부 /// </summary> private bool allowFloating = true; /// <summary> /// 더블 클릭시 플로팅 여부 /// </summary> private bool floatOnDblClick = true; /// <summary> /// 자동 숨김 버튼 표시 여부 /// </summary> private bool showAutoHideButton = true; /// <summary> /// 최대화 버튼 표시 여부 /// </summary> private bool showMaximizeButton = true; /// <summary> /// 닫기 버튼 표시 여부 /// </summary> private bool showCloseButton = true; /// <summary> /// 플로팅 위치 /// </summary> private Point? floatLocation = null; /// <summary> /// 플로팅 크기 /// </summary> private Size? floatSize = null; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 왼쪽 도킹 허용 여부 - AllowDockLeft /// <summary> /// 왼쪽 도킹 허용 여부 /// </summary> public bool AllowDockLeft { get { return this.allowDockLeft; } set { this.allowDockLeft = value; } } #endregion #region 위쪽 도킹 허용 여부 - AllowDockTop /// <summary> /// 위쪽 도킹 허용 여부 /// </summary> public bool AllowDockTop { get { return this.allowDockTop; } set { this.allowDockTop = value; } } #endregion #region 오른쪽 도킹 허용 여부 - AllowDockRight /// <summary> /// 오른쪽 도킹 허용 여부 /// </summary> public bool AllowDockRight { get { return this.allowDockRight; } set { this.allowDockRight = value; } } #endregion #region 아래쪽 도킹 허용 여부 - AllowDockBottom /// <summary> /// 아래쪽 도킹 허용 여부 /// </summary> public bool AllowDockBottom { get { return this.allowDockBottom; } set { this.allowDockBottom = value; } } #endregion #region 채우기 도킹 허용 여부 - AllowDockFill /// <summary> /// 채우기 도킹 허용 여부 /// </summary> public bool AllowDockFill { get { return this.allowDockFill; } set { this.allowDockFill = value; } } #endregion #region 플로팅 허용 여부 - AllowFloating /// <summary> /// 플로팅 허용 여부 /// </summary> public bool AllowFloating { get { return this.allowFloating; } set { this.allowFloating = value; } } #endregion #region 더블 클릭시 플로팅 여부 - FloatOnDblClick /// <summary> /// 더블 클릭시 플로팅 여부 /// </summary> public bool FloatOnDblClick { get { return this.floatOnDblClick; } set { this.floatOnDblClick = value; } } #endregion #region 자동 숨김 버튼 표시 여부 - ShowAutoHideButton /// <summary> /// 자동 숨김 버튼 표시 여부 /// </summary> public bool ShowAutoHideButton { get { return this.showAutoHideButton; } set { this.showAutoHideButton = value; } } #endregion #region 최대화 버튼 표시 여부 - ShowMaximizeButton /// <summary> /// 최대화 버튼 표시 여부 /// </summary> public bool ShowMaximizeButton { get { return this.showMaximizeButton; } set { this.showMaximizeButton = value; } } #endregion #region 닫기 버튼 표시 여부 - ShowCloseButton /// <summary> /// 닫기 버튼 표시 여부 /// </summary> public bool ShowCloseButton { get { return this.showCloseButton; } set { this.showCloseButton = value; } } #endregion #region 플로팅 위치 - FloatLocation /// <summary> /// 플로팅 위치 /// </summary> public Point? FloatLocation { get { return this.floatLocation; } set { this.floatLocation = value; } } #endregion #region 플로팅 크기 - FloatSize /// <summary> /// 플로팅 크기 /// </summary> public Size? FloatSize { get { return this.floatSize; } set { this.floatSize = value; } } #endregion } } |
▶ DocumentControl.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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
using System; using System.Collections.Generic; using System.Drawing; using System.Runtime.InteropServices; using System.Windows.Forms; using DevExpress.XtraBars.Docking; using DevExpress.XtraBars.Docking2010; using DevExpress.XtraBars.Docking2010.Views; using DevExpress.XtraBars.Docking2010.Views.Tabbed; namespace TestProject { /// <summary> /// 문서 컨트롤 /// </summary> public partial class DocumentControl : UserControl { //////////////////////////////////////////////////////////////////////////////////////////////////// Import ////////////////////////////////////////////////////////////////////////////////////////// Static //////////////////////////////////////////////////////////////////////////////// Private #region 사각형 무효화 하기 - InvalidateRect(windowHandle, rectangleHandle, erase) /// <summary> /// 사각형 무효화 하기 /// </summary> /// <param name="windowHandle">윈도우 핸들</param> /// <param name="rectangleHandle">사각형 핸들</param> /// <param name="erase">지우기 여부</param> /// <returns>처리 결과</returns> [DllImport("user32.dll")] private static extern bool InvalidateRect(IntPtr windowHandle, IntPtr rectangleHandle, bool erase); #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 도킹 패널 딕셔너리 /// </summary> private Dictionary<string, DockPanel> dictionary = new Dictionary<string, DockPanel>(); /// <summary> /// 문서 추가 여부 /// </summary> private bool isAddDocument = false; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - DocumentControl() /// <summary> /// 생성자 /// </summary> public DocumentControl() { InitializeComponent(); this.tabbedView.DocumentAdded += tabbedView_DocumentAdded; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Public #region 문서 추가하기 - AddDocument(name, text, contentControl, documentOption, dockStyle) /// <summary> /// 문서 추가하기 /// </summary> /// <param name="name">명칭</param> /// <param name="text">텍스트</param> /// <param name="contentControl">컨텐트 컨트롤</param> /// <param name="documentOption">문서 옵션</param> /// <param name="dockStyle">도킹 스타일</param> /// <returns>처리 결과</returns> public bool AddDocument ( string name, string text, Control contentControl, DocumentOption documentOption = null, DockStyle dockStyle = DockStyle.Fill ) { try { this.tabbedView.BeginUpdate(); this.dockManager.BeginUpdate(); this.isAddDocument = true; if(this.dictionary.ContainsKey(name)) { return false; } DockingStyle dockingStyle = GetDockingStyle(dockStyle); DockPanel dockPanel = this.dockManager.AddPanel(DockingStyle.Left); dockPanel.Name = name; dockPanel.Text = text; dockPanel.Appearance.BackColor = Color.White; if(documentOption != null) { SetDockPanel(dockPanel, documentOption); } CustomHeaderButton button = GetCustomHeaderButton(string.Empty, Properties.Resources.Undo); dockPanel.CustomHeaderButtons.Add(button); if(contentControl != null) { dockPanel.ControlContainer.Controls.Add(contentControl); } if(dockStyle == DockStyle.Fill || dockStyle == DockStyle.None) { try { dockPanel.DockedAsTabbedDocument = true; Document document = this.tabbedView.AddDocument(dockPanel) as Document; //RefreshScreen(); if(documentOption != null) { if(documentOption.FloatLocation.HasValue) { document.FloatLocation = documentOption.FloatLocation; } if(documentOption.FloatSize.HasValue) { document.FloatSize = documentOption.FloatSize; } } } finally { this.tabbedView.EndUpdate(); } } dockPanel.CustomButtonClick += dockPanel_CustomButtonClick; dockPanel.ClosedPanel += dockPanel_ClosedPanel; this.dictionary.Add(name, dockPanel); return true; } finally { this.isAddDocument = false; this.dockManager.EndUpdate(); this.tabbedView.EndUpdate(); } } #endregion #region 문서 수 구하기 - GetDocumentCount() /// <summary> /// 문서 수 구하기 /// </summary> /// <returns>문서 수</returns> public int GetDocumentCount() { int count = this.dockManager.Panels.Count; return count; } #endregion #region 문서 옵션 구하기 - GetDocumentOption(name) /// <summary> /// 문서 옵션 구하기 /// </summary> /// <param name="name">명칭</param> /// <returns>문서 옵션</returns> public DocumentOption GetDocumentOption(string name) { if(this.dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; DocumentOption documentOption = new DocumentOption(); SetDocumentOption(documentOption, dockPanel); return documentOption; } else { return null; } } #endregion #region 문서 옵션 구하기 - GetDocumentOption(index) /// <summary> /// 문서 옵션 구하기 /// </summary> /// <param name="index">인덱스</param> /// <returns>문서 옵션</returns> public DocumentOption GetDocumentOption(int index) { DockPanel dockPanel = this.dockManager.Panels[index]; DocumentOption documentOption = GetDocumentOption(dockPanel.Name); return documentOption; } #endregion #region 문서 옵션 설정하기 - ion(name, documentOption) /// <summary> /// 문서 옵션 설정하기 /// </summary> /// <param name="name">명칭</param> /// <param name="documentOption">문서 옵션</param> /// <returns>처리 결과</returns> public bool SetDocumentOption(string name, DocumentOption documentOption) { if(this.dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; SetDockPanel(dockPanel, documentOption); return true; } else { return false; } } #endregion #region 문서 옵션 설정하기 - SetDocumentOption(index, documentOption) /// <summary> /// 문서 옵션 설정하기 /// </summary> /// <param name="index">인덱스</param> /// <param name="documentOption">문서 옵션</param> /// <returns>처리 결과</returns> public bool SetDocumentOption(int index, DocumentOption documentOption) { DockPanel dockPanel = this.dockManager.Panels[index]; bool result = SetDocumentOption(dockPanel.Name, documentOption); return result; } #endregion #region 컨텐트 컨트롤 구하기 - GetContentControl(name) /// <summary> /// 컨텐트 컨트롤 구하기 /// </summary> /// <param name="name">명칭</param> /// <returns>컨텐트 컨트롤</returns> public Control GetContentControl(string name) { if(this.dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; if(dockPanel.ControlContainer.Controls.Count > 0) { return dockPanel.ControlContainer.Controls[0]; } else { return null; } } else { return null; } } #endregion #region 컨텐트 컨트롤 구하기 - GetContentControl(index) /// <summary> /// 컨텐트 컨트롤 구하기 /// </summary> /// <param name="index">인덱스</param> /// <returns>컨텐트 컨트롤</returns> public Control GetContentControl(int index) { DockPanel dockPanel = this.dockManager.Panels[index]; Control control = GetContentControl(dockPanel.Name); return control; } #endregion #region 문서 제거하기 - RemoveDocument(name) /// <summary> /// 문서 제거하기 /// </summary> /// <param name="name">명칭</param> /// <returns>처리 결과</returns> public bool RemoveDocument(string name) { if(this.dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; dockPanel.Close(); return true; } else { return false; } } #endregion #region 문서 제거하기 - RemoveDocument(index) /// <summary> /// 문서 제거하기 /// </summary> /// <param name="index">인덱스</param> /// <returns>처리 결과</returns> public bool RemoveDocument(int index) { DockPanel dockPanel = this.dockManager.Panels[index]; bool result = RemoveDocument(dockPanel.Name); return result; } #endregion #region 모든 문서들 제거하기 - RemoveAllDocuments() /// <summary> /// 모든 문서들 제거하기 /// </summary> public void RemoveAllDocuments() { try { this.dockManager.BeginUpdate(); this.dockManager.Clear(); this.dictionary.Clear(); } finally { this.dockManager.EndUpdate(); } } #endregion #region 플로팅 문서 여부 구하기 - IsFloatDocument(name) /// <summary> /// 플로팅 문서 여부 구하기 /// </summary> /// <param name="name">명칭</param> /// <returns>플로팅 문서 여부</returns> public bool IsFloatDocument(string name) { if(this.dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; return dockPanel.FloatForm != null; } else { return false; } } #endregion #region 플로팅 문서 여부 구하기 - IsFloatDocument(index) /// <summary> /// 플로팅 문서 여부 구하기 /// </summary> /// <param name="index">인덱스</param> /// <returns>플로팅 문서 여부</returns> public bool IsFloatDocument(int index) { DockPanel dockPanel = this.dockManager.Panels[index]; bool result = IsFloatDocument(dockPanel.Name); return result; } #endregion #region 플로팅 문서 만들기 - ToFloatDocument(name, floatLocation) /// <summary> /// 플로팅 문서 만들기 /// </summary> /// <param name="name">명칭</param> /// <param name="floatLocation">플로팅 위치</param> /// <returns>처리 결과</returns> public bool ToFloatDocument(string name, Point? floatLocation = null) { if(this.dictionary.ContainsKey(name)) { if(IsFloatDocument(name)) { return false; } DockPanel dockPanel = this.dictionary[name]; BaseDocument document = GetDocument(dockPanel); if(document == null) { dockPanel.MakeFloat(); return true; } else { this.documentManager.View.Controller.Float(document); return true; } } else { return false; } } #endregion #region 플로팅 문서 만들기 - ToFloatDocument(index, floatLocation) /// <summary> /// 플로팅 문서 만들기 /// </summary> /// <param name="index">인덱스</param> /// <param name="floatLocation">플로팅 위치</param> /// <returns>처리 결과</returns> public bool ToFloatDocument(int index, Point? floatLocation = null) { DockPanel dockPanel = this.dockManager.Panels[index]; bool result = ToFloatDocument(dockPanel.Name, floatLocation); return result; } #endregion #region 탭 문서 만들기 - ToTabbedDocument(name) /// <summary> /// 탭 문서 만들기 /// </summary> /// <param name="name">명칭</param> /// <returns>처리 결과</returns> public bool ToTabbedDocument(string name) { if(this.dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; if(IsFloatDocument(dockPanel.Name)) { try { this.tabbedView.BeginUpdate(); dockPanel.DockedAsTabbedDocument = true; this.tabbedView.AddDocument(dockPanel); } finally { this.tabbedView.EndUpdate(); } return true; } else { BaseDocument document = GetDocument(dockPanel); if(document == null) { try { this.tabbedView.BeginUpdate(); dockPanel.DockedAsTabbedDocument = true; this.tabbedView.AddDocument(dockPanel); } finally { this.tabbedView.EndUpdate(); } return true; } else { return false; } } } else { return false; } } #endregion #region 탭 문서 만들기 - ToTabbedDocument(index) /// <summary> /// 탭 문서 만들기 /// </summary> /// <param name="index">인덱스</param> /// <returns>처리 결과</returns> public bool ToTabbedDocument(int index) { DockPanel dockPanel = this.dockManager.Panels[index]; bool result = ToTabbedDocument(dockPanel.Name); return result; } #endregion #region 탭 문서 이동하기 - MoveTabbedDocument(name, position) /// <summary> /// 탭 문서 이동하기 /// </summary> /// <param name="name">명칭</param> /// <param name="position">위치</param> /// <returns>처리 결과</returns> public bool MoveTabbedDocument(string name, int position) { if(dictionary.ContainsKey(name)) { DockPanel dockPanel = this.dictionary[name]; if(IsFloatDocument(dockPanel.Name)) { return false; } else { Document document = GetDocument(dockPanel) as Document; if(document == null) { return false; } else { this.tabbedView.Controller.Move(document, position); return true; } } } else { return false; } } #endregion #region 탭 문서 이동하기 - MoveTabbedDocument(index, position) /// <summary> /// 탭 문서 이동하기 /// </summary> /// <param name="index">인덱스</param> /// <param name="position">위치</param> /// <returns>처리 결과</returns> public bool MoveTabbedDocument(int index, int position) { DockPanel dockPanel = this.dockManager.Panels[index]; bool result = MoveTabbedDocument(dockPanel.Name, position); return result; } #endregion ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 탭 뷰 문서 추가시 처리하기 - tabbedView_DocumentAdded(sender, e) /// <summary> /// 탭 뷰 문서 추가시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void tabbedView_DocumentAdded(object sender, DocumentEventArgs e) { if(!this.isAddDocument) { RefreshScreen(); } } #endregion #region 도킹 패널 커스텀 버튼 클릭시 처리하기 - dockPanel_CustomButtonClick(sender, e) /// <summary> /// 도킹 패널 커스텀 버튼 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void dockPanel_CustomButtonClick(object sender, ButtonEventArgs e) { DockPanel dockPanel = sender as DockPanel; try { this.tabbedView.BeginUpdate(); dockPanel.DockedAsTabbedDocument = true; Document document = this.tabbedView.AddDocument(dockPanel) as Document; RefreshScreen(); } finally { this.tabbedView.EndUpdate(); } } #endregion #region 도킹 패널 패널 닫힌 경우 처리하기 - dockPanel_ClosedPanel(sender, e) /// <summary> /// 도킹 패널 패널 닫힌 경우 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void dockPanel_ClosedPanel(object sender, DockPanelEventArgs e) { DockPanel dockPanel = sender as DockPanel; if(this.dictionary.ContainsKey(dockPanel.Name)) { this.dictionary.Remove(dockPanel.Name); } this.dockManager.RemovePanel(dockPanel); } #endregion //////////////////////////////////////////////////////////////////////////////// Function #region 커스텀 헤더 버튼 구하기 - GetCustomHeaderButton(caption, image) /// <summary> /// 커스텀 헤더 버튼 구하기 /// </summary> /// <param name="caption">제목</param> /// <param name="image">이미지</param> /// <returns>커스텀 헤더 버튼</returns> private CustomHeaderButton GetCustomHeaderButton(string caption, Image image) { CustomHeaderButton button = new CustomHeaderButton(caption, DevExpress.XtraBars.Docking2010.ButtonStyle.PushButton); button.Image = image; return button; } #endregion #region 도킹 패널 설정하기 - SetDockPanel(dockPanel, documentOption) /// <summary> /// 도킹 패널 설정하기 /// </summary> /// <param name="dockPanel">도킹 패널</param> /// <param name="documentOption">문서 옵션</param> /// <returns>처리 결과</returns> private bool SetDockPanel(DockPanel dockPanel, DocumentOption documentOption) { if(dockPanel == null || documentOption == null) { return false; } dockPanel.Options.AllowDockLeft = documentOption.AllowDockLeft; dockPanel.Options.AllowDockTop = documentOption.AllowDockTop; dockPanel.Options.AllowDockRight = documentOption.AllowDockRight; dockPanel.Options.AllowDockBottom = documentOption.AllowDockBottom; dockPanel.Options.AllowDockFill = documentOption.AllowDockFill; dockPanel.Options.AllowFloating = documentOption.AllowFloating; dockPanel.Options.FloatOnDblClick = documentOption.FloatOnDblClick; dockPanel.Options.ShowAutoHideButton = documentOption.ShowAutoHideButton; dockPanel.Options.ShowMaximizeButton = documentOption.ShowMaximizeButton; dockPanel.Options.ShowCloseButton = documentOption.ShowCloseButton; BaseDocument document = GetDocument(dockPanel); if(document != null) { if(documentOption.FloatLocation.HasValue) { document.FloatLocation = documentOption.FloatLocation; } if(documentOption.FloatSize.HasValue) { document.FloatSize = documentOption.FloatSize; } } return true; } #endregion #region 문서 옵션 설정하기 - SetDocumentOption(documentOption, dockPanel) /// <summary> /// 문서 옵션 설정하기 /// </summary> /// <param name="documentOption">문서 옵션</param> /// <param name="dockPanel">도킹 패널</param> /// <returns>처리 결과</returns> private bool SetDocumentOption(DocumentOption documentOption, DockPanel dockPanel) { if(documentOption == null || dockPanel == null) { return false; } documentOption.AllowDockLeft = dockPanel.Options.AllowDockLeft; documentOption.AllowDockTop = dockPanel.Options.AllowDockTop; documentOption.AllowDockRight = dockPanel.Options.AllowDockRight; documentOption.AllowDockBottom = dockPanel.Options.AllowDockBottom; documentOption.AllowDockFill = dockPanel.Options.AllowDockFill; documentOption.AllowFloating = dockPanel.Options.AllowFloating; documentOption.FloatOnDblClick = dockPanel.Options.FloatOnDblClick; documentOption.ShowAutoHideButton = dockPanel.Options.ShowAutoHideButton; documentOption.ShowMaximizeButton = dockPanel.Options.ShowMaximizeButton; documentOption.ShowCloseButton = dockPanel.Options.ShowCloseButton; BaseDocument document = GetDocument(dockPanel); if(document != null) { documentOption.FloatLocation = document.FloatLocation; documentOption.FloatSize = document.FloatSize; } else { documentOption.FloatLocation = null; documentOption.FloatSize = null; } return true; } #endregion #region 문서 구하기 - GetDocument(control) /// <summary> /// 문서 구하기 /// </summary> /// <param name="control">컨트롤</param> /// <returns>문서</returns> private BaseDocument GetDocument(Control control) { BaseDocument document = this.documentManager.GetDocument(control); return document; } #endregion #region 도킹 스타일 구하기 - GetDockingStyle(dockStyle) /// <summary> /// 도킹 스타일 구하기 /// </summary> /// <param name="dockStyle">도킹 스타일</param> /// <returns>도킹 스타일</returns> private DockingStyle GetDockingStyle(DockStyle dockStyle) { switch(dockStyle) { case DockStyle.Left : return DockingStyle.Left; case DockStyle.Top : return DockingStyle.Top; case DockStyle.Right : return DockingStyle.Right; case DockStyle.Bottom : return DockingStyle.Bottom; default : return DockingStyle.Float; } } #endregion #region 화면 갱신하기 - RefreshScreen() /// <summary> /// 화면 갱신하기 /// </summary> private void RefreshScreen() { InvalidateRect(IntPtr.Zero, IntPtr.Zero, true); } #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 95 96 97 98 99 100 101 102 103 104 105 106 107 |
using System; using System.Drawing; using System.Windows.Forms; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : Form { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Private #region Field /// <summary> /// 카운트 /// </summary> private int count = 1; #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.addDocumentButton1.Click += addDocumentButton1_Click; this.addDocumentButton2.Click += addDocumentButton2_Click; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private //////////////////////////////////////////////////////////////////////////////// Event #region 문서 추가 버튼 1 클릭시 처리하기 - addDocumentButton1_Click(sender, e) /// <summary> /// 문서 추가 버튼 1 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void addDocumentButton1_Click(object sender, EventArgs e) { string name = "panel" + this.count.ToString(); string text = "Panel" + this.count.ToString(); this.count++; //////////////////////////////////////// CONTENT CONTROL START Button button = new Button(); button.Name = "testButton"; button.Text = "TEST"; button.Size = new Size(100, 25); button.Location = new Point(50, 50); //////////////////////////////////////// CONTENT CONTROL END DocumentOption documentOption = new DocumentOption(); documentOption.AllowDockFill = false; this.firstDocumentControl.AddDocument(name, text, button, documentOption); } #endregion #region 문서 추가 버튼 2 클릭시 처리하기 - addDocumentButton2_Click(sender, e) /// <summary> /// 문서 추가 버튼 2 클릭시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void addDocumentButton2_Click(object sender, EventArgs e) { string name = "panel" + this.count.ToString(); string text = "Panel" + this.count.ToString(); this.count++; //////////////////////////////////////// CONTENT CONTROL START ComboBox comboBox = new ComboBox(); comboBox.Name = "testComboBox"; comboBox.Text = "TEST"; comboBox.Size = new Size(100, 25); comboBox.Location = new Point(50, 50); //////////////////////////////////////// CONTENT CONTROL END this.secondDocumentControl.AddDocument(name, text, comboBox); } #endregion } } |