Пример #1
0
        /// <summary>
        /// 重绘控件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (BackImg == null)
            {
                base.OnPaint(e);
                return;
            }

            if (!this.Enabled)
            {
                this.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
            }
            else
            {
                this.ForeColor = System.Drawing.SystemColors.ControlText;
            }

            int i = (int)state;

            if (this.Focused && state != State.MouseDown && _IsTabFocus == true)
            {
                i = 5;
            }
            if (!this.Enabled)
            {
                i = 4;
            }
            Rectangle rc = this.ClientRectangle;
            Graphics  g  = e.Graphics;



            base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle));
            try
            {
                //Color backimgcorlor = Color.Transparent;
                //// 绘制背景色
                //if (this.FindForm().BackColor != null)
                //{
                //    backimgcorlor = this.FindForm().BackColor;
                //}

                //if (this.FindForm().BackgroundImage != null)
                //{
                //    backimgcorlor = ((Bitmap)this.FindForm().BackgroundImage).GetPixel(10, 10);
                //}
                //backimgcorlor = Color.FromArgb(40, backimgcorlor);
                //using ( System.Drawing.SolidBrush backbrush=new System.Drawing.SolidBrush(backimgcorlor))
                //{
                //    Rectangle border = e.ClipRectangle;
                //    border.Width -= 2;
                //    border.Height -= 2;
                //    Rectangle rt = new Rectangle(border.Location.X + 1, border.Location.Y + 1, border.Width, border.Height);

                //    //填充绘制效果
                //    e.Graphics.FillRectangle(backbrush, rt);

                //}

                if (BackImg != null)
                {
                    if (_BacklightLTRB != Rectangle.Empty)
                    {
                        ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), i, 5);
                    }
                    else
                    {
                        ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(10, 10, 10, 10), i, 5);
                    }
                }
            }
            catch
            { }

            Image img = null;
            Size  txts, imgs;

            txts = Size.Empty;
            imgs = Size.Empty;

            if (this.Image != null)
            {
                img = this.Image;
            }
            else if (this.ImageList != null && this.ImageIndex != -1)
            {
                img = this.ImageList.Images[this.ImageIndex];
            }

            if (img != null)
            {
                imgs.Width  = img.Width;
                imgs.Height = img.Height;
            }

            StringFormat format1;

            using (format1 = new StringFormat())
            {
                format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
                SizeF ef1 = g.MeasureString(this.Text, this.Font, new SizeF((float)rc.Width, (float)rc.Height), format1);
                txts = Size.Ceiling(ef1);
            }

            rc.Inflate(-4, -4);
            if (imgs.Width * imgs.Height != 0)
            {
                Rectangle imgr = rc;
                imgr = ImageDrawRect.HAlignWithin(imgs, imgr, this.ImageAlign);
                imgr = ImageDrawRect.VAlignWithin(imgs, imgr, this.ImageAlign);
                if (!this.Enabled)
                {
                    ControlPaint.DrawImageDisabled(g, img, imgr.Left, imgr.Top, this.BackColor);
                }
                else
                {
                    g.DrawImage(img, imgr.Left, imgr.Top, img.Width, img.Height);
                }
            }

            Rectangle txtr = rc;

            txtr = ImageDrawRect.HAlignWithin(txts, txtr, this.TextAlign);
            txtr = ImageDrawRect.VAlignWithin(txts, txtr, this.TextAlign);

            format1 = new StringFormat();
            format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

            if (this.RightToLeft == RightToLeft.Yes)
            {
                format1.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }
            brush = new SolidBrush(this.ForeColor);
            g.DrawString(this.Text, this.Font, brush, (RectangleF)txtr, format1);
            brush.Dispose();
        }
Пример #2
0
        /// <summary>
        /// 重绘控件
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            if (BackImg == null)
            {
                base.OnPaint(e);
                return;
            }

            int i = (int)state;

            if (this.Focused && state != State.MouseDown && _IsTabFocus == true)
            {
                i = 5;
            }
            if (!this.Enabled)
            {
                i = 4;
            }
            Rectangle rc = this.ClientRectangle;
            Graphics  g  = e.Graphics;

            base.InvokePaintBackground(this, new PaintEventArgs(e.Graphics, base.ClientRectangle));
            try
            {
                if (BackImg != null)
                {
                    if (_BacklightLTRB != Rectangle.Empty)
                    {
                        ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(_BacklightLTRB.X, _BacklightLTRB.Y, _BacklightLTRB.Width, _BacklightLTRB.Height), i, 5);
                    }
                    else
                    {
                        ImageDrawRect.DrawRect(g, BackImg, rc, Rectangle.FromLTRB(10, 10, 10, 10), i, 5);
                    }
                }
            }
            catch
            { }

            Image img = null;
            Size  txts, imgs;

            txts = Size.Empty;
            imgs = Size.Empty;

            if (this.Image != null)
            {
                img = this.Image;
            }
            else if (this.ImageList != null && this.ImageIndex != -1)
            {
                img = this.ImageList.Images[this.ImageIndex];
            }

            if (img != null)
            {
                imgs.Width  = img.Width;
                imgs.Height = img.Height;
            }

            StringFormat format1;

            using (format1 = new StringFormat())
            {
                format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
                SizeF ef1 = g.MeasureString(this.Text, this.Font, new SizeF((float)rc.Width, (float)rc.Height), format1);
                txts = Size.Ceiling(ef1);
            }

            rc.Inflate(-4, -4);
            if (imgs.Width * imgs.Height != 0)
            {
                Rectangle imgr = rc;
                imgr = ImageDrawRect.HAlignWithin(imgs, imgr, this.ImageAlign);
                imgr = ImageDrawRect.VAlignWithin(imgs, imgr, this.ImageAlign);
                if (!this.Enabled)
                {
                    ControlPaint.DrawImageDisabled(g, img, imgr.Left, imgr.Top, this.BackColor);
                }
                else
                {
                    g.DrawImage(img, imgr.Left, imgr.Top, img.Width, img.Height);
                }
            }

            Rectangle txtr = rc;

            txtr = ImageDrawRect.HAlignWithin(txts, txtr, this.TextAlign);
            txtr = ImageDrawRect.VAlignWithin(txts, txtr, this.TextAlign);

            format1 = new StringFormat();
            format1.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

            if (this.RightToLeft == RightToLeft.Yes)
            {
                format1.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }
            brush = new SolidBrush(this.ForeColor);
            g.DrawString(this.Text, this.Font, brush, (RectangleF)txtr, format1);
            brush.Dispose();
        }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            Rectangle rectangle;
            Rectangle rectangle2;
            Color     controlDark;
            Color     color3;

            base.OnPaint(e);
            base.OnPaintBackground(e);
            Graphics  g = e.Graphics;
            Rectangle clientRectangle = base.ClientRectangle;

            this.CalculateRect(out rectangle, out rectangle2);
            g.SmoothingMode = SmoothingMode.AntiAlias;
            Color  baseColor        = this.BaseColor;
            Color  innerBorderColor = Color.FromArgb(200, 0xff, 0xff, 0xff);
            Bitmap mouseBack        = null;
            int    num = 0;

            if (this.StopState != StopStates.NoStop)
            {
                this._controlState = (ControlState)this.StopState;
            }
            if (this.InheritColor)
            {
                baseColor = base.Parent.BackColor;
            }
            switch (this._controlState)
            {
            case ControlState.Hover:
                mouseBack   = (Bitmap)this.MouseBack;
                controlDark = this.GetColor(baseColor, 0, -13, -8, -3);
                color3      = baseColor;
                break;

            case ControlState.Pressed:
                mouseBack   = (Bitmap)this.DownBack;
                controlDark = this.GetColor(baseColor, 0, -35, -24, -9);
                color3      = baseColor;
                num         = 1;
                break;

            default:
                mouseBack   = (Bitmap)this.NormlBack;
                controlDark = baseColor;
                color3      = baseColor;
                break;
            }
            if (!base.Enabled)
            {
                controlDark = SystemColors.ControlDark;
                color3      = SystemColors.ControlDark;
            }
            if ((mouseBack != null) && (this.DrawType == DrawStyle.Img))
            {
                SkinTools.CreateRegion(this, clientRectangle, this.Radius, this.RoundStyle);
                if (this.Create && (this._controlState != this.states))
                {
                    SkinTools.CreateControlRegion(this, mouseBack, 1);
                }
                if (this.Palace)
                {
                    ImageDrawRect.DrawRect(g, mouseBack, clientRectangle, Rectangle.FromLTRB(this.BackRectangle.X, this.BackRectangle.Y, this.BackRectangle.Width, this.BackRectangle.Height), 1, 1);
                }
                else
                {
                    g.DrawImage(mouseBack, 0, 0, base.Width, base.Height);
                }
            }
            else if (this.DrawType == DrawStyle.Draw)
            {
                this.RenderBackgroundInternal(g, clientRectangle, controlDark, color3, innerBorderColor, this.RoundStyle, this.Radius, 0.35f, true, true, LinearGradientMode.Vertical);
                if (this.FadeGlow)
                {
                    this.DrawButtonBackgroundFromBuffer(e.Graphics);
                }
            }
            Image image = null;
            Size  empty = Size.Empty;

            if (base.Image != null)
            {
                if (string.IsNullOrEmpty(this.Text))
                {
                    image = base.Image;
                    empty = new Size(image.Width, image.Height);
                    clientRectangle.Inflate(-4, -4);
                    if ((empty.Width * empty.Height) != 0)
                    {
                        Rectangle withinThis = clientRectangle;
                        withinThis = ImageDrawRect.HAlignWithin(empty, withinThis, base.ImageAlign);
                        withinThis = ImageDrawRect.VAlignWithin(empty, withinThis, base.ImageAlign);
                        if (!base.Enabled)
                        {
                            ControlPaint.DrawImageDisabled(g, image, withinThis.Left, withinThis.Top, this.BackColor);
                        }
                        else
                        {
                            g.DrawImage(image, withinThis.Left + num, withinThis.Top + num, image.Width, image.Height);
                        }
                    }
                }
                else
                {
                    g.InterpolationMode = InterpolationMode.HighQualityBilinear;
                    g.DrawImage(base.Image, rectangle, -num, -num, base.Image.Width, base.Image.Height, GraphicsUnit.Pixel);
                }
            }
            else if ((base.ImageList != null) && (base.ImageIndex != -1))
            {
                image = base.ImageList.Images[base.ImageIndex];
            }
            Color foreColor = base.Enabled ? this.ForeColor : SystemColors.ControlDark;

            if (this.ForeColorSuit)
            {
                if (SkinTools.ColorSlantsDarkOrBright(baseColor))
                {
                    foreColor = Color.White;
                }
                else
                {
                    foreColor = Color.Black;
                }
            }
            TextRenderer.DrawText(g, this.Text, this.Font, rectangle2, foreColor, GetTextFormatFlags(this.TextAlign, this.RightToLeft == RightToLeft.Yes));
            this.states = this._controlState;
        }