Esempio n. 1
0
        /// <summary>
        /// Raised when the form is painted
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            using (var buffer = new Bitmap(Bounds.Width, Bounds.Height))
            {
                using (var g = GraphicsEx.FromImage(buffer))
                {
                    g.GradientFill(
                        Bounds,
                        Color.DarkBlue,
                        Color.LightBlue,
                        GradientFillDirection.Vertical);

                    using (var font = FontFactory.CreateRotatedFont(Font.Name, 50))
                    {
                        var size = g.Surface.MeasureString(Text, font);
                        var x    = (Bounds.Width - size.Width) / 2f;

                        using (var brush = new SolidBrush(ForeColor))
                            g.Surface.DrawString(Text, font, brush, x, Dpi.Scale(5));
                    }
                }

                e.Graphics.DrawImage(buffer, 0, 0);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draws the Image
        /// </summary>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Parent == null && Image == null)
            {
                base.OnPaint(e);
                return;
            }

            using (var g = GraphicsEx.FromImage(MemoryBitmap))
            {
                var form = Parent as IControlBackground;
                if (!pushed)
                {
                    if (form != null && Transparent && form.BackgroundImage != null)
                    {
                        DrawBackground(g.Surface, form, Bounds, Parent);
                    }
                    else if (Parent != null)
                    {
                        g.Surface.Clear(Parent.BackColor);
                    }
                }

                if (Image != null)
                {
                    switch (SizeMode)
                    {
                    case PictureBoxSizeMode.Normal:
                        DrawNormal(g);
                        break;

                    case PictureBoxSizeMode.CenterImage:
                        DrawCentered(g);
                        break;

                    case PictureBoxSizeMode.StretchImage:
                        DrawStretched(g);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if (pushed && form != null && form.BackgroundImage != null)
                {
                    g.AlphaBlend(form.BackgroundImage, 170, Location.X, Location.Y);
                }
            }

            e.Graphics.DrawImage(MemoryBitmap, 0, 0);
        }
Esempio n. 3
0
        /// <summary>
        /// Draws the control
        /// </summary>
        /// <param name="e">Drawing surface data</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            using (var gxOff = GraphicsEx.FromImage(MemoryBitmap))
            {
                gxOff.Surface.Clear(Parent.BackColor);
                if (Environment.OSVersion.Platform != PlatformID.WinCE)
                {
                    gxOff.Surface.DrawRectangle(
                        border,
                        0, 0, ClientSize.Width - 1, ClientSize.Height - 1);
                }

                if (Pushed)
                {
                    gxOff.DrawRoundedRectangle(ClientRectangle, PressedColor);
                }

                DrawImage(gxOff);

                if (!string.IsNullOrEmpty(Text))
                {
                    var size = gxOff.Surface.MeasureString(Text, Font);
                    gxOff.Surface.DrawString(
                        Text,
                        Font,
                        text,
                        (ClientSize.Width - size.Width) / 2,
                        (ClientSize.Height - size.Height));
                }

                if (Transparent)
                {
                    try
                    {
                        var bgOwner = Parent as IControlBackground;
                        if (bgOwner != null && bgOwner.BackgroundImage != null)
                        {
                            gxOff.AlphaBlend(bgOwner.BackgroundImage, 70, Location.X, Location.Y);
                        }
                    }
                    catch (PlatformNotSupportedException ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }

            e.Graphics.DrawImage(MemoryBitmap, 0, 0);
        }
Esempio n. 4
0
        /// <summary>
        /// Draws the control
        /// </summary>
        /// <param name="e">Drawing surface data</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            using (var gxOff = GraphicsEx.FromImage(MemoryBitmap))
            {
                if (!Pushed)
                {
                    gxOff.GradientFill(ClientRectangle, GradientStart, GradientEnd, GradientFillDirection.Vertical);
                }
                else
                {
                    gxOff.GradientFill(ClientRectangle, GradientEnd, GradientStart, GradientFillDirection.Vertical);
                }

                gxOff.Surface.DrawRectangle(border, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1);

                if (!string.IsNullOrEmpty(Text))
                {
                    var size = gxOff.Surface.MeasureString(Text, Font);
                    gxOff.Surface.DrawString(
                        Text,
                        Font,
                        text,
                        (ClientSize.Width - size.Width) / 2,
                        (ClientSize.Height - size.Height) / 2);
                }

                if (Transparent)
                {
                    try
                    {
                        var bgOwner = Parent as IControlBackground;
                        if (bgOwner != null && bgOwner.BackgroundImage != null)
                        {
                            gxOff.AlphaBlend(bgOwner.BackgroundImage, 70, Location.X, Location.Y);
                        }
                    }
                    catch (PlatformNotSupportedException ex)
                    {
                        Debug.WriteLine(ex.Message);
                    }
                }
            }

            e.Graphics.DrawImage(MemoryBitmap, 0, 0);
        }
Esempio n. 5
0
        /// <summary>
        /// Draws the control
        /// </summary>
        /// <param name="e">Drawing surface data</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            using (var gxOff = GraphicsEx.FromImage(MemoryBitmap))
            {
                var topRect    = new Rectangle(0, 0, ClientSize.Width, ClientSize.Height / 2);
                var bottomRect = new Rectangle(0, topRect.Height, ClientSize.Width, ClientSize.Height / 2);

                if (!Pushed)
                {
                    switch (ColorTheme)
                    {
                    case ButtonTheme.Black:
                        gxOff.GradientFill(bottomRect, Color.FromArgb(0, 0, 11), Color.FromArgb(32, 32, 32), GradientFillDirection.Vertical);
                        gxOff.GradientFill(topRect, Color.FromArgb(176, 176, 176), Color.FromArgb(32, 32, 32), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Red:
                        gxOff.GradientFill(bottomRect, Color.FromArgb(11, 0, 0), Color.FromArgb(32, 0, 0), GradientFillDirection.Vertical);
                        gxOff.GradientFill(topRect, Color.FromArgb(176, 0, 0), Color.FromArgb(32, 0, 0), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Green:
                        gxOff.GradientFill(bottomRect, Color.FromArgb(0, 11, 0), Color.FromArgb(0, 32, 0), GradientFillDirection.Vertical);
                        gxOff.GradientFill(topRect, Color.FromArgb(0, 176, 0), Color.FromArgb(0, 32, 0), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Blue:
                        gxOff.GradientFill(bottomRect, Color.FromArgb(0, 0, 11), Color.FromArgb(0, 0, 11), GradientFillDirection.Vertical);
                        gxOff.GradientFill(topRect, Color.FromArgb(0, 0, 176), Color.FromArgb(0, 0, 32), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Default:
                        throw new NotImplementedException("This feature is yet to be implemented");

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                {
                    switch (ColorTheme)
                    {
                    case ButtonTheme.Black:
                        gxOff.GradientFill(topRect, Color.FromArgb(0, 0, 11), Color.FromArgb(32, 32, 32), GradientFillDirection.Vertical);
                        gxOff.GradientFill(bottomRect, Color.FromArgb(176, 176, 176), Color.FromArgb(32, 32, 32), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Red:
                        gxOff.GradientFill(topRect, Color.FromArgb(11, 0, 0), Color.FromArgb(32, 0, 0), GradientFillDirection.Vertical);
                        gxOff.GradientFill(bottomRect, Color.FromArgb(176, 0, 0), Color.FromArgb(32, 0, 0), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Green:
                        gxOff.GradientFill(topRect, Color.FromArgb(0, 11, 0), Color.FromArgb(0, 32, 0), GradientFillDirection.Vertical);
                        gxOff.GradientFill(bottomRect, Color.FromArgb(0, 176, 0), Color.FromArgb(0, 32, 0), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Blue:
                        gxOff.GradientFill(topRect, Color.FromArgb(0, 0, 11), Color.FromArgb(0, 0, 11), GradientFillDirection.Vertical);
                        gxOff.GradientFill(bottomRect, Color.FromArgb(0, 0, 176), Color.FromArgb(0, 0, 32), GradientFillDirection.Vertical);
                        break;

                    case ButtonTheme.Default:
                        throw new NotImplementedException("This feature is yet to be implemented");

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                gxOff.Surface.DrawRectangle(border, 0, 0, ClientSize.Width - 1, ClientSize.Height - 1);

                if (!string.IsNullOrEmpty(Text))
                {
                    var size = gxOff.Surface.MeasureString(Text, Font);
                    gxOff.Surface.DrawString(
                        Text,
                        Font,
                        text,
                        (ClientSize.Width - size.Width) / 2,
                        (ClientSize.Height - size.Height) / 2);
                }

                if (Transparent)
                {
                    try
                    {
                        var bgOwner = Parent as IControlBackground;
                        if (bgOwner != null && bgOwner.BackgroundImage != null)
                        {
                            gxOff.AlphaBlend(bgOwner.BackgroundImage, 70, Location.X, Location.Y);
                        }
                    }
                    catch (PlatformNotSupportedException)
                    {
                        Debug.WriteLine("AlphaBlend is not a supported GDI feature on this device");
                    }
                }
            }

            e.Graphics.DrawImage(MemoryBitmap, 0, 0);
        }