BaseContentsFormRelease.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. namespace LYFZ.ComponentLibrary
  10. {
  11. /// <summary>
  12. /// 测试窗体,请不要使用,内容基窗体
  13. /// </summary>
  14. public partial class BaseContentsFormRelease : BaseForm360
  15. {
  16. /// <summary>
  17. /// 设置是否使用自定义滚动条
  18. /// </summary>
  19. /// <param name="isCustomScrollBar">设置是否使用自定义滚动条</param>
  20. public BaseContentsFormRelease()
  21. {
  22. InitializeComponent();
  23. this.btnAppFormMenu.MouseClick += new MouseEventHandler(btnAppFormMenu_MouseClick);
  24. // this.ctlScrollBarH.Scroll += new EventHandler(ctlScrollBarH_Scroll);
  25. // this.ctlScrollBarV.Scroll += new EventHandler(ctlScrollBarV_Scroll);
  26. this.plExMainContainer.Resize += new EventHandler(plExMainContainer_Resize);
  27. this.plFormMainContent.Resize+=new EventHandler(plFormMainContent_Resize);
  28. this.Resize += new EventHandler(BaseContentsFormRelease_Resize);
  29. this.Shown += new EventHandler(BaseContentsFormRelease_Shown);
  30. // IsCustomScrollBar = false;
  31. }
  32. /// <summary>
  33. /// 记录滚动条显示时需要的宽度
  34. /// </summary>
  35. int PanlOffset = 0;
  36. /// <summary>
  37. /// 首次显示时
  38. /// </summary>
  39. /// <param name="sender"></param>
  40. /// <param name="e"></param>
  41. void BaseContentsFormRelease_Shown(object sender, EventArgs e)
  42. {
  43. if (IsCustomScrollBar)
  44. {
  45. PanlOffset = 20;
  46. }
  47. SetplExMainContainerSize(PanlOffset);
  48. SetScrollBarAttr();
  49. InitializeScrollBar();
  50. }
  51. /// <summary>
  52. /// 窗体大小变化时
  53. /// </summary>
  54. /// <param name="sender"></param>
  55. /// <param name="e"></param>
  56. void BaseContentsFormRelease_Resize(object sender, EventArgs e)
  57. {
  58. SetplExMainContainerSize(PanlOffset);
  59. SetScrollBarAttr();
  60. InitializeScrollBar();
  61. }
  62. /// <summary>
  63. /// 父panl大小变化时
  64. /// </summary>
  65. /// <param name="sender"></param>
  66. /// <param name="e"></param>
  67. void plFormMainContent_Resize(object sender, EventArgs e)
  68. {
  69. SetplExMainContainerSize(PanlOffset);
  70. SetScrollBarAttr();
  71. InitializeScrollBar();
  72. }
  73. /// <summary>
  74. /// 子panl大小变化时
  75. /// </summary>
  76. /// <param name="sender"></param>
  77. /// <param name="e"></param>
  78. void plExMainContainer_Resize(object sender, EventArgs e)
  79. {
  80. if (!this.TopLevel)
  81. {
  82. SetplExMainContainerSize(PanlOffset);
  83. SetScrollBarAttr();
  84. InitializeScrollBar();
  85. }
  86. }
  87. //两个变量记录水平或垂直方向的滚动条位置,已达到同步效果
  88. int scrollX = 0;
  89. int scrollY = 0;
  90. bool isShowCtlScrollBarV = false;//记录是否显示垂直滚动条
  91. bool isShowCtlScrollBarH = false;//记录日否显示水平滚动条
  92. void ctlScrollBarV_Scroll(object sender, EventArgs e)
  93. {
  94. //垂直滚动
  95. // scrollY = ctlScrollBarV.Value;
  96. // this.plExMainContainer.AutoScrollPosition = new Point(scrollX, ctlScrollBarV.Value);
  97. }
  98. void ctlScrollBarH_Scroll(object sender, EventArgs e)
  99. {
  100. //水平滚动
  101. // scrollX = ctlScrollBarH.Value;
  102. // this.plExMainContainer.AutoScrollPosition = new Point(ctlScrollBarH.Value, scrollY);
  103. }
  104. /// <summary>
  105. /// 重绘控件
  106. /// </summary>
  107. /// <param name="e"></param>
  108. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  109. {
  110. base.OnPaint(e);
  111. SetplExMainContainerSize(PanlOffset);
  112. }
  113. /// <summary>
  114. /// 设置内容容器的大小和位置
  115. /// </summary>
  116. public void SetplExMainContainerSize(int offset=0)
  117. {
  118. try
  119. {
  120. //父panl大小和位置
  121. this.plFormMainContent.Location = new Point(0, this.TitleBgImageHeight);
  122. //子panl大小和位置
  123. isShowCtlScrollBarH = this.plExMainContainer.HorizontalScroll.Visible;
  124. isShowCtlScrollBarV = this.plExMainContainer.VerticalScroll.Visible;
  125. if (IsCustomScrollBar)
  126. {
  127. if (isShowCtlScrollBarV)
  128. {
  129. // this.ctlScrollBarV.Visible = true;
  130. this.plFormMainContent.Width = this.Width - offset;
  131. this.plExMainContainer.Width = this.plFormMainContent.Width + offset - 4;
  132. }
  133. else
  134. {
  135. // this.ctlScrollBarV.Visible = false;
  136. this.plFormMainContent.Width = this.Width;
  137. this.plExMainContainer.Width = this.plFormMainContent.Width;
  138. }
  139. if (isShowCtlScrollBarH)
  140. {
  141. // this.ctlScrollBarH.Visible = true;
  142. this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight - offset;
  143. this.plExMainContainer.Height = this.plFormMainContent.Height + offset - 4;
  144. }
  145. else
  146. {
  147. // this.ctlScrollBarH.Visible = false;
  148. this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight;
  149. this.plExMainContainer.Height = this.plFormMainContent.Height;
  150. }
  151. }
  152. else
  153. {
  154. this.plFormMainContent.Width = this.Width;
  155. this.plFormMainContent.Height = this.Height - this.TitleBgImageHeight - this.BottomBgImageHeight;
  156. this.plExMainContainer.Width = this.plFormMainContent.Width;
  157. this.plExMainContainer.Height = this.plFormMainContent.Height;
  158. }
  159. }
  160. catch { }
  161. }
  162. /// <summary>
  163. /// 初始化滚动条
  164. /// </summary>
  165. public void InitializeScrollBar()
  166. {
  167. try
  168. {
  169. this.plExMainContainer.AutoScrollPosition = new Point(scrollX, scrollY);
  170. // this.ctlScrollBarV.Minimum = 0;
  171. // this.ctlScrollBarV.Maximum = this.plExMainContainer.DisplayRectangle.Height;
  172. // this.ctlScrollBarV.LargeChange = ctlScrollBarV.Maximum / ctlScrollBarV.Height + this.plExMainContainer.Height - 20;
  173. // this.ctlScrollBarV.Value = Math.Abs(this.plExMainContainer.AutoScrollPosition.Y);
  174. // this.ctlScrollBarH.Minimum = 0;
  175. // this.ctlScrollBarH.Maximum = this.plExMainContainer.DisplayRectangle.Width;
  176. // this.ctlScrollBarH.LargeChange = ctlScrollBarH.Maximum / ctlScrollBarH.Width + this.plExMainContainer.Width - 20;
  177. // this.ctlScrollBarH.Value = Math.Abs(this.plExMainContainer.AutoScrollPosition.X);
  178. }
  179. catch { }
  180. }
  181. /// <summary>
  182. /// 设置滚动条属性
  183. /// </summary>
  184. void SetScrollBarAttr()
  185. {
  186. if (IsCustomScrollBar)
  187. {
  188. // this.ctlScrollBarV.Location = new Point(this.plFormMainContent.Width, this.plFormMainContent.Location.Y);
  189. // this.ctlScrollBarH.Location = new Point(0, this.plFormMainContent.Location.Y + this.plFormMainContent.Height);
  190. // this.ctlScrollBarV.Size = new Size(this.ctlScrollBarV.Width, this.plFormMainContent.Height);
  191. // this.ctlScrollBarH.Size = new Size(this.plFormMainContent.Width, this.ctlScrollBarH.Height);
  192. // scrollX = this.ctlScrollBarH.Value;
  193. // scrollY = this.ctlScrollBarV.Value;
  194. }
  195. }
  196. bool isCustomScrollBar = false;
  197. /// <summary>
  198. /// 设置是否使用自定义滚动条
  199. /// </summary>
  200. [Browsable(false), Category("自定义窗体属性"), Description("设置是否使用自定义滚动条")]
  201. public bool IsCustomScrollBar
  202. {
  203. get { return isCustomScrollBar; }
  204. // set { isCustomScrollBar = value; }
  205. }
  206. private void btnAppFormMenu_MouseClick(object sender, MouseEventArgs e)
  207. {
  208. Button btn = sender as Button;
  209. Point point = new Point();
  210. point.Y = btn.Height;
  211. if (e.Button == MouseButtons.Left)
  212. {
  213. this.cmsSystemMeunList.Show(btn, point);
  214. }
  215. }
  216. private void tsmAbout_Click(object sender, EventArgs e)
  217. {
  218. frmSystemAbout frmAbout = new frmSystemAbout();
  219. frmAbout.ShowDialog(this);
  220. }
  221. }
  222. }