You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

175 lines
4.6 KiB

  1. #if NETFX || NETCORE
  2. using System;
  3. using System.Windows.Forms;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. namespace Apewer.Surface
  7. {
  8. /// <summary>基本控件。</summary>
  9. public class BaseControl : UserControl
  10. {
  11. #region this
  12. /// <summary>组件。</summary>
  13. protected IContainer _components = null;
  14. /// <summary>释放资源。</summary>
  15. public new void Dispose()
  16. {
  17. if (!_disposed)
  18. {
  19. base.Dispose();
  20. _disposed = true;
  21. }
  22. }
  23. /// <summary>释放资源。</summary>
  24. protected override void Dispose(bool disposing)
  25. {
  26. if (disposing && (_components != null)) _components.Dispose();
  27. base.Dispose(disposing);
  28. }
  29. /// <summary>初始化组件。</summary>
  30. protected void InitializeComponent()
  31. {
  32. _components = new Container();
  33. this.AutoScaleMode = AutoScaleMode.None;
  34. this.Font = DefaultFont;
  35. this.Size = new Size(300, 300);
  36. this.VerticalScroll.SmallChange = 20;
  37. this.VerticalScroll.LargeChange = 40;
  38. //this.BackColor = System.Drawing.Color.White;
  39. //this.MouseWheel += event_caption_mousewheel;
  40. //this.MouseMove += event_caption_mousemove;
  41. }
  42. /// <summary>构造函数。</summary>
  43. public BaseControl()
  44. {
  45. Optimization = true;
  46. this.VerticalScroll.SmallChange = 10;
  47. this.VerticalScroll.LargeChange = 20;
  48. this.HorizontalScroll.SmallChange = 10;
  49. this.HorizontalScroll.LargeChange = 20;
  50. this.MouseWheel += Event_Caption_MouseWheel;
  51. this.MouseMove += Event_Caption_MouseMove;
  52. this.HandleCreated += Event_HandleCreated;
  53. this.HandleDestroyed += Event_HandleDestroyed;
  54. }
  55. #endregion
  56. #region variable
  57. private int _index = 0;
  58. private string _key = "";
  59. private bool _locked = false;
  60. private bool _basecreated = false;
  61. private bool _disposed = false;
  62. #endregion
  63. #region accessor
  64. /// <summary>界面线程调用器。</summary>
  65. protected delegate void Invoker();
  66. /// <summary>已改变锁定属性。</summary>
  67. public event EventHandler LockedChanged;
  68. /// <summary>索引。</summary>
  69. public virtual int Index
  70. {
  71. get { return _index; }
  72. set { _index = value; }
  73. }
  74. /// <summary>标识。</summary>
  75. public virtual string Key
  76. {
  77. get { return _key; }
  78. set { _key = string.IsNullOrEmpty(value) ? "" : value; }
  79. }
  80. /// <summary>锁定。</summary>
  81. public virtual bool Locked
  82. {
  83. get { return _locked; }
  84. set
  85. {
  86. bool vold = _locked;
  87. _locked = value;
  88. if ((vold != value) && (LockedChanged != null)) LockedChanged(this, new EventArgs());
  89. }
  90. }
  91. /// <summary>基对象已创建。</summary>
  92. public bool BaseCreated
  93. {
  94. get { return _basecreated; }
  95. private set { _basecreated = value; }
  96. }
  97. /// <summary>鼠标滚轮事件。</summary>
  98. public void WheelMouse(MouseEventArgs e)
  99. {
  100. OnMouseWheel(e);
  101. }
  102. /// <summary>启用优化。</summary>
  103. protected virtual bool Optimization
  104. {
  105. set
  106. {
  107. SetStyle(ControlStyles.UserPaint, value);
  108. SetStyle(ControlStyles.AllPaintingInWmPaint, value);
  109. SetStyle(ControlStyles.OptimizedDoubleBuffer, value);
  110. // SetStyle(ControlStyles.ResizeRedraw, value);
  111. SetStyle(ControlStyles.DoubleBuffer, value);
  112. UpdateStyles();
  113. }
  114. }
  115. #endregion
  116. #region event
  117. private void Event_Caption_MouseMove(object sender, MouseEventArgs e)
  118. {
  119. // if (AutoScroll) Focus();
  120. }
  121. private void Event_Caption_MouseWheel(object sender, MouseEventArgs e)
  122. {
  123. if (AutoScroll)
  124. {
  125. //Refresh();
  126. //Invalidate();
  127. //Update();
  128. }
  129. }
  130. private void Event_HandleDestroyed(object sender, EventArgs e)
  131. {
  132. BaseCreated = false;
  133. }
  134. private void Event_HandleCreated(object sender, EventArgs e)
  135. {
  136. BaseCreated = true;
  137. }
  138. #endregion
  139. }
  140. }
  141. #endif