using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Windows.Forms; namespace POSV.Component { [ToolboxItem(true)] public partial class ControlBoxExt : BaseUserControl { public ControlBoxExt() { InitializeComponent(); this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor , true); this.ForeColor = NewForeColor; } protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (this.DesignMode) return; } private string _text = "新窗口"; /// /// 窗口标题 /// public override string Text { set { this._text = value; this.lblTitle.Text = _text; this.lblTitle.Invalidate(); } get { return this._text; } } public event EventHandler CloseClick; /// /// 关闭按钮事件 /// /// protected virtual void OnCloseClick(EventArgs e) { this._eventAction = ControlBoxEventAction.Closed; CloseClick?.Invoke(this , e); } public event EventHandler MinimizedClick; /// /// 最小化按钮事件 /// /// protected virtual void OnMinimizedClick(EventArgs e) { this._eventAction = ControlBoxEventAction.Minimized; MinimizedClick?.Invoke(this , e); } private void OnMinTouchClick(object sender , EventArgs e) { OnMinimizedClick(e); } private void OnCloseTouchClick(object sender , EventArgs e) { OnCloseClick(e); } private ControlBoxEventAction _eventAction = ControlBoxEventAction.None; public ControlBoxEventAction Action { get { return _eventAction; } } private Color _foreColor = Color.White; /// /// 标题的字体颜色 /// public Color NewForeColor { get { return this._foreColor; } set { this._foreColor = value; this.lblTitle.ForeColor = this._foreColor; this.lblTitle.Invalidate(); this.lblClose.SymbolColor = this._foreColor; this.lblMin.SymbolColor = this._foreColor; } } private bool _minimizeBox = true; /// /// 是否显示最小化按钮 /// public bool MinimizeBox { get { return this._minimizeBox; } set { this._minimizeBox = value; this.lblMin.Visible = this._minimizeBox; } } private bool _closeBox = true; /// /// 是否显示关闭按钮 /// public bool CloseBox { get { return this._closeBox; } set { this._closeBox = value; this.lblClose.Visible = this._closeBox; } } private bool _showNetworkStatus = true; /// /// 是否显示网路连接 /// public bool ShowNetworkStatus { get { return this._showNetworkStatus; } set { this._showNetworkStatus = value; this.lblNetworkStatus.Visible = this._showNetworkStatus; this.lblNetworkStatus.Invalidate(); } } private bool _network = false; /// /// 网络检测默认的标题文字 /// public bool NetworkStatus { set { this._network = value; this.lblNetworkStatus.Symbol = value ? Constant.ONLINE : Constant.OFFLINE; this.lblNetworkStatus.SymbolColor = value ? Color.Green : Color.Red; this.lblNetworkStatus.Invalidate(); } get { return this._network; } } } public enum ControlBoxExtEventAction { None = 0, Minimized = 1, Closed = 2 } }