Пример #1
0
 protected virtual void OnPaintBackground(FluidPaintEventArgs e)
 {
     if (PaintBackground != null)
     {
         PaintBackground(this, e);
     }
     else
     {
         if (!BackColor.IsEmpty && BackColor != Color.Transparent)
         {
             Graphics g = e.Graphics;
             if (BackColor.A == 255 || BackColor.A == 0)
             {
                 SolidBrush brush = Brushes.GetBrush(BackColor);
                 g.FillRectangle(brush, e.ControlBounds);
             }
             else
             {
                 using (GraphicsPlus gp = new GraphicsPlus(g))
                 {
                     using (SolidBrushPlus brush = new SolidBrushPlus(BackColor))
                     {
                         gp.FillRectangle(brush, e.ControlBounds);
                     }
                 }
             }
         }
     }
 }
Пример #2
0
        protected override void PaintText(FluidPaintEventArgs e)
        {
            if (focused)
            {
                Graphics g = e.Graphics;
                if (SelectBounds.IsEmpty)
                {
                    SelectBounds = GetSelectBounds(startSel, selCount);
                }
                Rectangle bounds  = e.ControlBounds;
                Rectangle selRect = SelectBounds;
                selRect.Offset(e.ScaleX(3), 0);
                selRect.Offset(bounds.X, bounds.Y);
                if (selRect.Width > 1)
                {
                    g.FillRectangle(Brushes.GetBrush(Color.SkyBlue), selRect);
                }
                else
                {
                    selRect.Width = 1;
                    g.FillRectangle(Brushes.GetBrush(Color.Black), selRect);
                }
            }

            string text = GetDisplayText();

            if (!string.IsNullOrEmpty(text))
            {
                PaintDefaultText(e, text);
            }
        }
Пример #3
0
        protected void PaintDefaultContent(FluidPaintEventArgs e)
        {
            Rectangle rect     = ButtonRectangle;
            Color     endColor = this.BackColor;
            Graphics  g        = e.Graphics;

            rect.Offset(e.ControlBounds.X, e.ControlBounds.Y);
            Color textColor = ForeColor;

            if (IsDown)
            {
                textColor = pressedForeColor.IsEmpty ? ColorConverter.AlphaBlendColor(endColor, textColor, 200) : pressedForeColor;
            }
            if (!Enabled)
            {
                textColor = ColorConverter.AlphaBlendColor(endColor, textColor, 32);
            }
            Brush        foreBrush = Brushes.GetBrush(textColor);
            StringFormat sf        = this.stringFormat;
            Rectangle    r         = rect;

            r.Inflate(e.ScaleX(-3), e.ScaleY(2));
            RectangleF rf = new RectangleF(r.Left, r.Top, r.Width, r.Height);

            if (IsDown)
            {
                rf.X++;
                rf.Y++;
            }

            rf.X += (float)ScaleX(TextOffset.X);
            rf.Y += (float)ScaleY(TextOffset.Y);

            g.DrawString(Text, Font, foreBrush, rf, sf);

            if (Image != null)
            {
                int imW = ScaleX(Image.Width);
                int imH = ScaleY(Image.Height);

                int w = Math.Min(imW, rect.Width);
                int h = Math.Min(imH, rect.Height);

                rect.Y     += (rect.Height - h) / 2;
                rect.X     += (rect.Width - h) / 2;
                rect.Width  = w;
                rect.Height = h;
                ImageAttributes ia = new ImageAttributes();
                ia.SetColorKey(Color.Fuchsia, Color.Fuchsia);
                if (rect.Width > w)
                {
                    rect.X    += (rect.Width - w) / 2;
                    rect.Width = w;
                }
                if (rect.Height > h)
                {
                    rect.X     += (rect.Height - h) / 2;
                    rect.Height = h;
                }
                if (IsDown)
                {
                    rect.X++;
                    rect.Y++;
                }
                g.DrawImage(Image, rect, 0, 0, Image.Width, Image.Height, GraphicsUnit.Pixel, ia);
                //                g.DrawImage(Image, rect, new Rectangle(0, 0, imW, imH), GraphicsUnit.Pixel);
            }
        }