#if NETFX || NETCORE
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
namespace Apewer.Surface
{
/// 基本控件。
public class BaseControl : UserControl
{
#region this
/// 组件。
protected IContainer _components = null;
/// 释放资源。
public new void Dispose()
{
if (!_disposed)
{
base.Dispose();
_disposed = true;
}
}
/// 释放资源。
protected override void Dispose(bool disposing)
{
if (disposing && (_components != null)) _components.Dispose();
base.Dispose(disposing);
}
/// 初始化组件。
protected void InitializeComponent()
{
_components = new Container();
this.AutoScaleMode = AutoScaleMode.None;
this.Font = DefaultFont;
this.Size = new Size(300, 300);
this.VerticalScroll.SmallChange = 20;
this.VerticalScroll.LargeChange = 40;
//this.BackColor = System.Drawing.Color.White;
//this.MouseWheel += event_caption_mousewheel;
//this.MouseMove += event_caption_mousemove;
}
/// 构造函数。
public BaseControl()
{
Optimization = true;
this.VerticalScroll.SmallChange = 10;
this.VerticalScroll.LargeChange = 20;
this.HorizontalScroll.SmallChange = 10;
this.HorizontalScroll.LargeChange = 20;
this.MouseWheel += Event_Caption_MouseWheel;
this.MouseMove += Event_Caption_MouseMove;
this.HandleCreated += Event_HandleCreated;
this.HandleDestroyed += Event_HandleDestroyed;
}
#endregion
#region variable
private int _index = 0;
private string _key = "";
private bool _locked = false;
private bool _basecreated = false;
private bool _disposed = false;
#endregion
#region accessor
/// 界面线程调用器。
protected delegate void Invoker();
/// 已改变锁定属性。
public event EventHandler LockedChanged;
/// 索引。
public virtual int Index
{
get { return _index; }
set { _index = value; }
}
/// 标识。
public virtual string Key
{
get { return _key; }
set { _key = string.IsNullOrEmpty(value) ? "" : value; }
}
/// 锁定。
public virtual bool Locked
{
get { return _locked; }
set
{
bool vold = _locked;
_locked = value;
if ((vold != value) && (LockedChanged != null)) LockedChanged(this, new EventArgs());
}
}
/// 基对象已创建。
public bool BaseCreated
{
get { return _basecreated; }
private set { _basecreated = value; }
}
/// 鼠标滚轮事件。
public void WheelMouse(MouseEventArgs e)
{
OnMouseWheel(e);
}
/// 启用优化。
protected virtual bool Optimization
{
set
{
SetStyle(ControlStyles.UserPaint, value);
SetStyle(ControlStyles.AllPaintingInWmPaint, value);
SetStyle(ControlStyles.OptimizedDoubleBuffer, value);
// SetStyle(ControlStyles.ResizeRedraw, value);
SetStyle(ControlStyles.DoubleBuffer, value);
UpdateStyles();
}
}
#endregion
#region event
private void Event_Caption_MouseMove(object sender, MouseEventArgs e)
{
// if (AutoScroll) Focus();
}
private void Event_Caption_MouseWheel(object sender, MouseEventArgs e)
{
if (AutoScroll)
{
//Refresh();
//Invalidate();
//Update();
}
}
private void Event_HandleDestroyed(object sender, EventArgs e)
{
BaseCreated = false;
}
private void Event_HandleCreated(object sender, EventArgs e)
{
BaseCreated = true;
}
#endregion
}
}
#endif