⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wndlesscontrol.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace Imps.Client.Pc.WndlessControls
{
    using System;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    public class WndlessControl : IDisposable
    {
        private AnchorStyles _anchor = (AnchorStyles.Left | AnchorStyles.Top);
        private bool _autosize = true;
        private Color _backColor = Color.Transparent;
        private Image _backImage;
        private Color _borderColor = Color.DarkGray;
        private System.Windows.Forms.BorderStyle _borderStyle = System.Windows.Forms.BorderStyle.None;
        private Rectangle _bounds;
        private System.Windows.Forms.Cursor _cursor;
        private bool _enabled = true;
        private System.Drawing.Font _font = SystemFonts.get_DefaultFont();
        private Color _foreColor = SystemColors.ControlText;
        private bool _isDown;
        private bool _isHover;
        private Padding _margin = Padding.Empty;
        private System.Drawing.Size _maxSize;
        private System.Drawing.Size _minSize;
        private WndlessControlCollection _ownedCol;
        private string _text = string.Empty;
        private ToolTip _tooltip;
        private string _tooltipText = string.Empty;
        private bool _visible = true;
        public GetBrushDelegate GetCustomizedBackgroundBrush;

        public event EventHandler BoundsChanged;

        public event EventHandler Click;

        public event EventHandler LocationChanged;

        public event EventHandler SizeChanged;

        public virtual void Dispose()
        {
            if (this._font != null)
            {
                this._font.Dispose();
            }
        }

        protected void DoAutoSize(bool invalidate)
        {
            if (this.AutoSize)
            {
                int x;
                int y;
                System.Drawing.Size preferredSize = this.PreferredSize;
                System.Drawing.Size size = this.Size;
                if ((this.Anchor & AnchorStyles.Left) == AnchorStyles.None)
                {
                    if ((this.Anchor & AnchorStyles.Right) == AnchorStyles.None)
                    {
                        x = this.Left + ((size.Width - preferredSize.Width) / 2);
                    }
                    else
                    {
                        x = this.Left + (size.Width - preferredSize.Width);
                    }
                }
                else
                {
                    x = this.Left;
                }
                if ((this.Anchor & AnchorStyles.Top) == AnchorStyles.None)
                {
                    if ((this.Anchor & AnchorStyles.Bottom) == AnchorStyles.None)
                    {
                        y = this.Top + ((size.Height - preferredSize.Height) / 2);
                    }
                    else
                    {
                        y = this.Top + (size.Height - preferredSize.Height);
                    }
                }
                else
                {
                    y = this.Top;
                }
                Rectangle a = this.Bounds;
                this.SetBounds(x, y, preferredSize.Width, preferredSize.Height, BoundsSpecified.All);
                if (invalidate && (this.OwnerControl != null))
                {
                    a = Rectangle.Union(a, this.Bounds);
                    this.Invalidate(a);
                }
            }
        }

        protected virtual string GetRealToolTipText()
        {
            return this._tooltipText;
        }

        internal void InnerDoMouseClick(MouseEventArgs e)
        {
            this.OnMouseClick(e);
        }

        internal void InnerDoMouseEnter(EventArgs e)
        {
            this.OnMouseEnter(e);
        }

        internal void InnerDoMouseHover(EventArgs e)
        {
            this.OnMouseHover(e);
            if ((this.ToolTipText.Length > 0) && (this._tooltip == null))
            {
                this._tooltip = new ToolTip();
                this._tooltip.Show(this.ToolTipText, this.OwnerControl, 0x2710);
            }
        }

        internal void InnerDoMouseLeave(EventArgs e)
        {
            this.OnMouseLeave(e);
            if (this._tooltip != null)
            {
                this._tooltip.Hide(this.OwnerControl);
                this._tooltip.Dispose();
                this._tooltip = null;
            }
        }

        internal void InnerDoMouseMove(MouseEventArgs e)
        {
            this.OnMouseMove(e);
        }

        internal void InnerDraw(PaintEventArgs e)
        {
            if (e.ClipRectangle.IntersectsWith(this.Bounds))
            {
                this.OnPaintBackground(e);
                this.OnPaint(e);
            }
        }

        internal bool InnerHitTest(Point pt)
        {
            if (((this._bounds.Left <= pt.X) && (this._bounds.Right >= pt.X)) && (this._bounds.Top <= pt.Y))
            {
                return (this._bounds.Bottom >= pt.Y);
            }
            return false;
        }

        private void InnerInit()
        {
            this._foreColor = SystemColors.ControlText;
            this._font = SystemFonts.get_DefaultFont();
        }

        public void Invalidate()
        {
            this.Invalidate(this.Bounds);
        }

        public void Invalidate(Rectangle rc)
        {
            if (this.OwnedCollection != null)
            {
                this.OwnedCollection.Invalidate(rc);
            }
        }

        internal static void InvalidateOwnerControl(Control ownerCtrl, Rectangle rc)
        {
            if (ownerCtrl != null)
            {
                ownerCtrl.Invalidate(rc);
            }
        }

        protected virtual void OnBoundsChanged(EventArgs e)
        {
            EventHandler boundsChanged = this.BoundsChanged;
            if (boundsChanged != null)
            {
                boundsChanged(this, e);
            }
        }

        protected virtual void OnClick(EventArgs e)
        {
            EventHandler click = this.Click;
            if (click != null)
            {
                click(this, e);
            }
        }

        protected virtual void OnLocationChanged(EventArgs e)
        {
            EventHandler locationChanged = this.LocationChanged;
            if (locationChanged != null)
            {
                locationChanged(this, e);
            }
        }

        protected virtual void OnMouseClick(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.OnClick(EventArgs.Empty);
            }
        }

        protected virtual void OnMouseEnter(EventArgs e)
        {
        }

        protected virtual void OnMouseHover(EventArgs e)
        {
        }

        protected virtual void OnMouseLeave(EventArgs e)
        {
        }

        protected virtual void OnMouseMove(MouseEventArgs e)
        {
        }

        protected virtual void OnPaint(PaintEventArgs e)
        {
        }

        protected virtual void OnPaintBackground(PaintEventArgs e)
        {
            GetBrushDelegate getCustomizedBackgroundBrush = this.GetCustomizedBackgroundBrush;
            if (getCustomizedBackgroundBrush != null)
            {
                bool disposeAfterUsed = false;
                Brush brush = getCustomizedBackgroundBrush(this, ref disposeAfterUsed);
                if (brush != null)
                {
                    e.Graphics.FillRectangle(brush, this.Bounds);
                    if (disposeAfterUsed)
                    {
                        brush.Dispose();
                    }
                }
            }
            else
            {
                if (this._backImage != null)
                {
                    using (TextureBrush brush2 = new TextureBrush(this._backImage, WrapMode.Tile))
                    {
                        e.Graphics.FillRectangle(brush2, this.Bounds);
                        goto Label_00AC;
                    }
                }
                if (this.BackColor != Color.Transparent)
                {
                    using (Brush brush3 = new SolidBrush(this.BackColor))
                    {
                        e.Graphics.FillRectangle(brush3, this.Bounds);
                    }
                }
            }
        Label_00AC:
            if (this.BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle)
            {
                ControlPaint.DrawBorder(e.Graphics, this.Bounds, this.BorderColor, ButtonBorderStyle.Solid);
            }
            else if (this.BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
            {
                ControlPaint.DrawBorder3D(e.Graphics, this.Bounds);
            }
        }

        protected virtual void OnSizeChanged(EventArgs e)
        {
            EventHandler sizeChanged = this.SizeChanged;
            if (sizeChanged != null)
            {
                sizeChanged(this, e);
            }
        }

        public void SetBounds(int x, int y, int width, int height, BoundsSpecified specified)
        {
            if ((specified & BoundsSpecified.X) == BoundsSpecified.None)
            {
                x = this.Left;
            }
            if ((specified & BoundsSpecified.Y) == BoundsSpecified.None)
            {
                y = this.Top;
            }
            if ((specified & BoundsSpecified.Width) == BoundsSpecified.None)
            {
                width = this.Width;
            }
            else if (!this.MaximumSize.IsEmpty && (width > this.MaximumSize.Width))
            {
                width = this.MaximumSize.Width;
            }
            else if (width < this.MinimumSize.Width)
            {
                width = this.MinimumSize.Width;
            }
            if ((specified & BoundsSpecified.Height) == BoundsSpecified.None)
            {
                height = this.Height;
            }
            else if (!this.MaximumSize.IsEmpty && (height > this.MaximumSize.Height))
            {
                height = this.MaximumSize.Height;
            }
            else if (height < this.MinimumSize.Height)
            {
                height = this.MinimumSize.Height;
            }
            bool flag = (this.Width != width) || (this.Height != height);
            bool flag2 = (this.Left != x) || (this.Top != y);
            if (flag2 || flag)
            {
                int left = x;
                int top = y;
                int right = x + width;
                int bottom = y + height;
                if (this.Left < left)
                {
                    left = this.Left;
                }
                if (this.Top < top)
                {
                    top = this.Top;
                }
                if (this.Right > right)
                {
                    right = this.Right;
                }
                if (this.Bottom > bottom)
                {
                    bottom = this.Bottom;
                }
                this._bounds = new Rectangle(x, y, width, height);
                if (flag2)
                {
                    this.OnLocationChanged(EventArgs.Empty);
                }
                if (flag)
                {
                    this.OnSizeChanged(EventArgs.Empty);
                }
                this.OnBoundsChanged(EventArgs.Empty);
            }
        }

        internal void SetIsDown(bool value)
        {
            if (this._isDown != value)
            {
                this._isDown = value;
                if (this.DoInvalidateWhenHover)
                {
                    this.Invalidate();
                }
            }
        }

        internal void SetIsHover(bool value)
        {
            if (this._isHover != value)
            {
                this._isHover = value;
                if (this.DoInvalidateWhenHover)
                {
                    this.Invalidate();
                }
            }
        }

        public virtual void UpdateAll()
        {
            this.DoAutoSize(true);
        }

        public AnchorStyles Anchor
        {
            get
            {
                return this._anchor;
            }
            set
            {
                this._anchor = value;
            }
        }

        public bool AutoSize
        {
            get
            {
                return this._autosize;
            }
            set
            {
                if (this._autosize != value)
                {
                    this._autosize = value;
                    this.DoAutoSize(true);
                }
            }
        }

        public Color BackColor
        {
            get
            {
                return this._backColor;
            }
            set
            {
                if (this._borderColor != value)
                {
                    this._backColor = value;
                    this.Invalidate();
                }
            }
        }

        public Image BackgroundImage
        {
            get
            {
                return this._backImage;
            }
            set
            {
                if (this._backImage != value)
                {
                    this._backImage = value;
                    this.Invalidate();
                }
            }
        }

        public Color BorderColor
        {
            get
            {
                return this._borderColor;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -