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

C#编程

开发平台:

C#

  1. using System;
  2. using System.ComponentModel;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Runtime.InteropServices;
  6. using System.Diagnostics.CodeAnalysis;
  7. namespace WeifenLuo.WinFormsUI.Docking
  8. {
  9. public class DockContent : Form, IDockContent
  10. {
  11. public DockContent()
  12. {
  13. m_dockHandler = new DockContentHandler(this, new GetPersistStringCallback(GetPersistString));
  14. m_dockHandler.DockStateChanged += new EventHandler(DockHandler_DockStateChanged);
  15. //Suggested as a fix by bensty regarding form resize
  16.             this.ParentChanged += new EventHandler(DockContent_ParentChanged);
  17. }
  18. //Suggested as a fix by bensty regarding form resize
  19.         private void DockContent_ParentChanged(object Sender, EventArgs e)
  20.         {
  21.             if (this.Parent != null)
  22.                 this.Font = this.Parent.Font;
  23. }
  24. private DockContentHandler m_dockHandler = null;
  25. [Browsable(false)]
  26. public DockContentHandler DockHandler
  27. {
  28. get { return m_dockHandler; }
  29. }
  30. [LocalizedCategory("Category_Docking")]
  31. [LocalizedDescription("DockContent_AllowEndUserDocking_Description")]
  32. [DefaultValue(true)]
  33. public bool AllowEndUserDocking
  34. {
  35. get { return DockHandler.AllowEndUserDocking; }
  36. set { DockHandler.AllowEndUserDocking = value; }
  37. }
  38. [LocalizedCategory("Category_Docking")]
  39. [LocalizedDescription("DockContent_DockAreas_Description")]
  40. [DefaultValue(DockAreas.DockLeft|DockAreas.DockRight|DockAreas.DockTop|DockAreas.DockBottom|DockAreas.Document|DockAreas.Float)]
  41. public DockAreas DockAreas
  42. {
  43. get { return DockHandler.DockAreas; }
  44. set { DockHandler.DockAreas = value; }
  45. }
  46. [LocalizedCategory("Category_Docking")]
  47. [LocalizedDescription("DockContent_AutoHidePortion_Description")]
  48. [DefaultValue(0.25)]
  49. public double AutoHidePortion
  50. {
  51. get { return DockHandler.AutoHidePortion; }
  52. set { DockHandler.AutoHidePortion = value; }
  53. }
  54. [Localizable(true)]
  55. [LocalizedCategory("Category_Docking")]
  56. [LocalizedDescription("DockContent_TabText_Description")]
  57. [DefaultValue(null)]
  58.         private string m_tabText = null;
  59. public string TabText
  60. {
  61.             get { return m_tabText; }
  62.             set { DockHandler.TabText = m_tabText = value; }
  63. }
  64. private bool ShouldSerializeTabText()
  65. {
  66. return (m_tabText != null);
  67. }
  68. [LocalizedCategory("Category_Docking")]
  69. [LocalizedDescription("DockContent_CloseButton_Description")]
  70. [DefaultValue(true)]
  71. public bool CloseButton
  72. {
  73. get { return DockHandler.CloseButton; }
  74. set { DockHandler.CloseButton = value; }
  75. }
  76.         [LocalizedCategory("Category_Docking")]
  77.         [LocalizedDescription("DockContent_CloseButtonVisible_Description")]
  78.         [DefaultValue(true)]
  79.         public bool CloseButtonVisible
  80.         {
  81.             get { return DockHandler.CloseButtonVisible; }
  82.             set { DockHandler.CloseButtonVisible = value; }
  83.         }
  84. [Browsable(false)]
  85. public DockPanel DockPanel
  86. {
  87. get { return DockHandler.DockPanel; }
  88. set { DockHandler.DockPanel = value; }
  89. }
  90. [Browsable(false)]
  91. public DockState DockState
  92. {
  93. get { return DockHandler.DockState; }
  94. set { DockHandler.DockState = value; }
  95. }
  96. [Browsable(false)]
  97. public DockPane Pane
  98. {
  99. get { return DockHandler.Pane; }
  100. set { DockHandler.Pane = value; }
  101. }
  102. [Browsable(false)]
  103. public bool IsHidden
  104. {
  105. get { return DockHandler.IsHidden; }
  106. set { DockHandler.IsHidden = value; }
  107. }
  108. [Browsable(false)]
  109. public DockState VisibleState
  110. {
  111. get { return DockHandler.VisibleState; }
  112. set { DockHandler.VisibleState = value; }
  113. }
  114. [Browsable(false)]
  115. public bool IsFloat
  116. {
  117. get { return DockHandler.IsFloat; }
  118. set { DockHandler.IsFloat = value; }
  119. }
  120. [Browsable(false)]
  121. public DockPane PanelPane
  122. {
  123. get { return DockHandler.PanelPane; }
  124. set { DockHandler.PanelPane = value; }
  125. }
  126. [Browsable(false)]
  127. public DockPane FloatPane
  128. {
  129. get { return DockHandler.FloatPane; }
  130. set { DockHandler.FloatPane = value; }
  131. }
  132.         [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
  133.         protected virtual string GetPersistString()
  134. {
  135.             return GetType().ToString();
  136. }
  137. [LocalizedCategory("Category_Docking")]
  138. [LocalizedDescription("DockContent_HideOnClose_Description")]
  139. [DefaultValue(false)]
  140. public bool HideOnClose
  141. {
  142. get { return DockHandler.HideOnClose; }
  143. set { DockHandler.HideOnClose = value; }
  144. }
  145. [LocalizedCategory("Category_Docking")]
  146. [LocalizedDescription("DockContent_ShowHint_Description")]
  147. [DefaultValue(DockState.Unknown)]
  148. public DockState ShowHint
  149. {
  150. get { return DockHandler.ShowHint; }
  151. set { DockHandler.ShowHint = value; }
  152. }
  153. [Browsable(false)]
  154. public bool IsActivated
  155. {
  156. get { return DockHandler.IsActivated; }
  157. }
  158. public bool IsDockStateValid(DockState dockState)
  159. {
  160. return DockHandler.IsDockStateValid(dockState);
  161. }
  162. [LocalizedCategory("Category_Docking")]
  163. [LocalizedDescription("DockContent_TabPageContextMenu_Description")]
  164. [DefaultValue(null)]
  165. public ContextMenu TabPageContextMenu
  166. {
  167. get { return DockHandler.TabPageContextMenu; }
  168. set { DockHandler.TabPageContextMenu = value; }
  169. }
  170.         [LocalizedCategory("Category_Docking")]
  171.         [LocalizedDescription("DockContent_TabPageContextMenuStrip_Description")]
  172.         [DefaultValue(null)]
  173.         public ContextMenuStrip TabPageContextMenuStrip
  174.         {
  175.             get { return DockHandler.TabPageContextMenuStrip; }
  176.             set { DockHandler.TabPageContextMenuStrip = value; }
  177.         }
  178. [Localizable(true)]
  179. [Category("Appearance")]
  180. [LocalizedDescription("DockContent_ToolTipText_Description")]
  181. [DefaultValue(null)]
  182. public string ToolTipText
  183. {
  184. get { return DockHandler.ToolTipText; }
  185. set { DockHandler.ToolTipText = value; }
  186. }
  187. public new void Activate()
  188. {
  189. DockHandler.Activate();
  190. }
  191. public new void Hide()
  192. {
  193. DockHandler.Hide();
  194. }
  195. public new void Show()
  196. {
  197. DockHandler.Show();
  198. }
  199. public void Show(DockPanel dockPanel)
  200. {
  201. DockHandler.Show(dockPanel);
  202. }
  203. public void Show(DockPanel dockPanel, DockState dockState)
  204. {
  205. DockHandler.Show(dockPanel, dockState);
  206. }
  207.         [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
  208. public void Show(DockPanel dockPanel, Rectangle floatWindowBounds)
  209. {
  210. DockHandler.Show(dockPanel, floatWindowBounds);
  211. }
  212. public void Show(DockPane pane, IDockContent beforeContent)
  213. {
  214. DockHandler.Show(pane, beforeContent);
  215. }
  216. public void Show(DockPane previousPane, DockAlignment alignment, double proportion)
  217. {
  218. DockHandler.Show(previousPane, alignment, proportion);
  219. }
  220.         [SuppressMessage("Microsoft.Naming", "CA1720:AvoidTypeNamesInParameters")]
  221.         public void FloatAt(Rectangle floatWindowBounds)
  222.         {
  223.             DockHandler.FloatAt(floatWindowBounds);
  224.         }
  225.         public void DockTo(DockPane paneTo, DockStyle dockStyle, int contentIndex)
  226.         {
  227.             DockHandler.DockTo(paneTo, dockStyle, contentIndex);
  228.         }
  229.         public void DockTo(DockPanel panel, DockStyle dockStyle)
  230.         {
  231.             DockHandler.DockTo(panel, dockStyle);
  232.         }
  233. #region IDockContent Members
  234. void IDockContent.OnActivated(EventArgs e)
  235. {
  236. this.OnActivated(e);
  237. }
  238. void IDockContent.OnDeactivate(EventArgs e)
  239. {
  240. this.OnDeactivate(e);
  241. }
  242. #endregion
  243. #region Events
  244. private void DockHandler_DockStateChanged(object sender, EventArgs e)
  245. {
  246. OnDockStateChanged(e);
  247. }
  248. private static readonly object DockStateChangedEvent = new object();
  249. [LocalizedCategory("Category_PropertyChanged")]
  250. [LocalizedDescription("Pane_DockStateChanged_Description")]
  251. public event EventHandler DockStateChanged
  252. {
  253. add { Events.AddHandler(DockStateChangedEvent, value); }
  254. remove { Events.RemoveHandler(DockStateChangedEvent, value); }
  255. }
  256. protected virtual void OnDockStateChanged(EventArgs e)
  257. {
  258. EventHandler handler = (EventHandler)Events[DockStateChangedEvent];
  259. if (handler != null)
  260. handler(this, e);
  261. }
  262. #endregion
  263. }
  264. }