DockAreasEditor.cs
上传用户:szlfmled
上传日期:2020-11-22
资源大小:978k
文件大小:5k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Drawing.Design;
  5. using System.Windows.Forms;
  6. using System.Windows.Forms.Design;
  7. namespace WeifenLuo.WinFormsUI.Docking
  8. {
  9. internal class DockAreasEditor : UITypeEditor
  10. {
  11. private class DockAreasEditorControl : System.Windows.Forms.UserControl
  12. {
  13. private CheckBox checkBoxFloat;
  14. private CheckBox checkBoxDockLeft;
  15. private CheckBox checkBoxDockRight;
  16. private CheckBox checkBoxDockTop;
  17. private CheckBox checkBoxDockBottom;
  18. private CheckBox checkBoxDockFill;
  19. private DockAreas m_oldDockAreas;
  20. public DockAreas DockAreas
  21. {
  22. get
  23. {
  24. DockAreas dockAreas = 0;
  25. if (checkBoxFloat.Checked)
  26. dockAreas |= DockAreas.Float;
  27. if (checkBoxDockLeft.Checked)
  28. dockAreas |= DockAreas.DockLeft;
  29. if (checkBoxDockRight.Checked)
  30. dockAreas |= DockAreas.DockRight;
  31. if (checkBoxDockTop.Checked)
  32. dockAreas |= DockAreas.DockTop;
  33. if (checkBoxDockBottom.Checked)
  34. dockAreas |= DockAreas.DockBottom;
  35. if (checkBoxDockFill.Checked)
  36. dockAreas |= DockAreas.Document;
  37. if (dockAreas == 0)
  38. return m_oldDockAreas;
  39. else
  40. return dockAreas;
  41. }
  42. }
  43. public DockAreasEditorControl()
  44. {
  45. checkBoxFloat = new CheckBox();
  46. checkBoxDockLeft = new CheckBox();
  47. checkBoxDockRight = new CheckBox();
  48. checkBoxDockTop = new CheckBox();
  49. checkBoxDockBottom = new CheckBox();
  50. checkBoxDockFill = new CheckBox();
  51. SuspendLayout();
  52. checkBoxFloat.Appearance = Appearance.Button;
  53. checkBoxFloat.Dock = DockStyle.Top;
  54. checkBoxFloat.Height = 24;
  55. checkBoxFloat.Text = Strings.DockAreaEditor_FloatCheckBoxText;
  56. checkBoxFloat.TextAlign = ContentAlignment.MiddleCenter;
  57. checkBoxFloat.FlatStyle = FlatStyle.System;
  58. checkBoxDockLeft.Appearance = System.Windows.Forms.Appearance.Button;
  59. checkBoxDockLeft.Dock = System.Windows.Forms.DockStyle.Left;
  60. checkBoxDockLeft.Width = 24;
  61. checkBoxDockLeft.FlatStyle = FlatStyle.System;
  62. checkBoxDockRight.Appearance = System.Windows.Forms.Appearance.Button;
  63. checkBoxDockRight.Dock = System.Windows.Forms.DockStyle.Right;
  64. checkBoxDockRight.Width = 24;
  65. checkBoxDockRight.FlatStyle = FlatStyle.System;
  66. checkBoxDockTop.Appearance = System.Windows.Forms.Appearance.Button;
  67. checkBoxDockTop.Dock = System.Windows.Forms.DockStyle.Top;
  68. checkBoxDockTop.Height = 24;
  69. checkBoxDockTop.FlatStyle = FlatStyle.System;
  70. checkBoxDockBottom.Appearance = System.Windows.Forms.Appearance.Button;
  71. checkBoxDockBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
  72. checkBoxDockBottom.Height = 24;
  73. checkBoxDockBottom.FlatStyle = FlatStyle.System;
  74. checkBoxDockFill.Appearance = System.Windows.Forms.Appearance.Button;
  75. checkBoxDockFill.Dock = System.Windows.Forms.DockStyle.Fill;
  76. checkBoxDockFill.FlatStyle = FlatStyle.System;
  77. this.Controls.AddRange(new Control[] {
  78.  checkBoxDockFill,
  79.  checkBoxDockBottom,
  80.  checkBoxDockTop,
  81.  checkBoxDockRight,
  82.  checkBoxDockLeft,
  83.  checkBoxFloat});
  84. Size = new System.Drawing.Size(160, 144);
  85. BackColor = SystemColors.Control;
  86. ResumeLayout();
  87. }
  88. public void SetStates(DockAreas dockAreas)
  89. {
  90. m_oldDockAreas = dockAreas;
  91. if ((dockAreas & DockAreas.DockLeft) != 0)
  92. checkBoxDockLeft.Checked = true;
  93. if ((dockAreas & DockAreas.DockRight) != 0)
  94. checkBoxDockRight.Checked = true;
  95. if ((dockAreas & DockAreas.DockTop) != 0)
  96. checkBoxDockTop.Checked = true;
  97. if ((dockAreas & DockAreas.DockTop) != 0)
  98. checkBoxDockTop.Checked = true;
  99. if ((dockAreas & DockAreas.DockBottom) != 0)
  100. checkBoxDockBottom.Checked = true;
  101. if ((dockAreas & DockAreas.Document) != 0)
  102. checkBoxDockFill.Checked = true;
  103. if ((dockAreas & DockAreas.Float) != 0)
  104. checkBoxFloat.Checked = true;
  105. }
  106. }
  107. private DockAreasEditor.DockAreasEditorControl m_ui = null;
  108. public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
  109. {
  110. return UITypeEditorEditStyle.DropDown;
  111. }
  112. public override object EditValue(ITypeDescriptorContext context, IServiceProvider sp, object value)
  113. {
  114. if (m_ui == null)
  115. m_ui = new DockAreasEditor.DockAreasEditorControl();
  116. m_ui.SetStates((DockAreas)value);
  117.             IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)sp.GetService(typeof(IWindowsFormsEditorService));
  118. edSvc.DropDownControl(m_ui);
  119. return m_ui.DockAreas;
  120. }
  121. }
  122. }