예제 #1
0
        private void RenderBorder(Graphics g, Rectangle bounds)
        {
            if (ShowBorder == false) return;

            if (RoundStyle == RoundStyle.None)
            {
                
                ControlPaint.DrawBorder(
                    g,
                    bounds,
                    ColorTable.Border,
                    ButtonBorderStyle.Solid);
            }
            else
            {
                using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
                {
                    using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                        bounds, Radius, RoundStyle, true))
                    {
                        using (Pen pen = new Pen(ColorTable.Border))
                        {
                            g.DrawPath(pen, path);
                        }
                    }
                }
            }
        }
예제 #2
0
        private void RenderImageAndText(Graphics g, Rectangle captionRect)
        {
            Rectangle imageRect = Rectangle.Empty;
            Rectangle textRect = Rectangle.Empty;
            int bordWidth = base.BorderWidth;
            int imageWidth = CaptionHeight - 6;

            StringFormat sf = new StringFormat();
            sf.FormatFlags = StringFormatFlags.NoWrap;
            sf.Trimming = StringTrimming.EllipsisCharacter;

            bool rightToLeft = base.RightToLeft == RightToLeft.Yes;
            bool drawImage = Owner.ImageStyle == CaptionImageStyle.Draw ||
                Owner.ImageStyle == CaptionImageStyle.Image;

            if (rightToLeft)
            {
                sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

            if (drawImage)
            {
                imageRect = new Rectangle(
                    bordWidth, captionRect.Y + 3, imageWidth, imageWidth);
            }
            else
            {
                imageRect.X = bordWidth - 3;
            }

            textRect = new Rectangle(
                imageRect.Right + 3,
                captionRect.Y,
                captionRect.Width - (imageRect.Right + 3) - bordWidth,
                captionRect.Height);

            if (rightToLeft)
            {
                imageRect.X = captionRect.Right - imageRect.Right;
                textRect.X = captionRect.Right - textRect.Right;
            }

            sf.LineAlignment = StringAlignment.Center;

            switch (TextAlign)
            {
                case ContentAlignment.BottomCenter:
                case ContentAlignment.MiddleCenter:
                case ContentAlignment.TopCenter:
                    sf.Alignment = StringAlignment.Center;
                    break;
                case ContentAlignment.BottomLeft:
                case ContentAlignment.MiddleLeft:
                case ContentAlignment.TopLeft:
                    sf.Alignment = StringAlignment.Near;
                    break;
                case ContentAlignment.BottomRight:
                case ContentAlignment.MiddleRight:
                case ContentAlignment.TopRight:
                    sf.Alignment = StringAlignment.Far;
                    break;
            }

            if (!string.IsNullOrEmpty(base.Text))
            {
                using (Brush brush = new SolidBrush(ColorTable.CaptionFore))
                {
                    g.DrawString(
                        base.Text,
                        CaptionFont,
                        brush,
                        textRect,
                        sf);
                }
            }

            if (drawImage)
            {
                if (Owner.ImageStyle == CaptionImageStyle.Image)
                {
                    Image image = _isExpanded ? 
                        Owner.ExpandImage : Owner.CollapseImage;
                    if (image != null)
                    {
                        g.DrawImage(
                            image,
                            imageRect,
                            0,
                            0,
                            image.Width,
                            image.Height,
                            GraphicsUnit.Pixel);
                    }
                }
                else
                {
                    ArrowDirection direction = _isExpanded ?
                        ArrowDirection.Up : ArrowDirection.Down;
                    using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
                    {
                        using (Brush brush = new SolidBrush(ColorTable.CaptionFore))
                        {
                            RenderHelper.RenderArrowInternal(
                                g,
                                imageRect,
                                direction,
                                brush);
                        }
                    }
                }
            }
        }
예제 #3
0
        protected override void OnPaintCaption(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle captionRect = CaptionRect;
            LinearGradientMode gradientMode = LinearGradientMode.Vertical;
            RoundStyle roundStyle = RoundStyle.All;

            Color backColor;
            switch (CaptionState)
            {
                case ControlState.Hover:
                    backColor = ColorTable.CaptionBackHover;
                    break;
                case ControlState.Pressed:
                    backColor = ColorTable.CaptionBackPressed;
                    break;
                default:
                    backColor = ColorTable.CaptionBackNormal;
                    break;
            }

            using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
            {
                RenderHelper.RenderBackgroundInternal(
                    g,
                    captionRect,
                    backColor,
                    ColorTable.Border,
                    Color.White,
                    roundStyle,
                    Radius,
                    true,
                    true,
                    gradientMode);
            }

            RenderImageAndText(g, captionRect);

            RenderBorder(g, base.ClientRectangle);
        }
예제 #4
0
        internal void RenderBorder(Graphics g, Rectangle bounds)
        {
            switch (_captionStyle)
            {
                case CaptionStyle.Top:
                case CaptionStyle.Bottom:
                    if (base.Height <= _captionHeight)
                    {
                        return;
                    }
                    break;
                case CaptionStyle.Left:
                case CaptionStyle.Right:
                    if (base.Width <= _captionHeight)
                    {
                        return;
                    }
                    break;
            }

            if (_showBorder)
            {
                if (RoundStyle == RoundStyle.None)
                {
                    ControlPaint.DrawBorder(
                        g,
                        bounds,
                        ColorTable.Border,
                        ButtonBorderStyle.Solid);
                }
                else
                {
                    using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                            bounds, Radius, RoundStyle, true))
                        {
                            using (Pen pen = new Pen(ColorTable.Border))
                            {
                                g.DrawPath(pen, path);
                            }
                        }
                    }
                }
            }
        }
예제 #5
0
        protected virtual void OnPaintCaption(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle captionRect = CaptionRect;
            LinearGradientMode gradientMode = LinearGradientMode.Vertical;
            RoundStyle roundStyle = RoundStyle.None;

            switch (_captionStyle)
            {
                case CaptionStyle.Top:
                    roundStyle = RoundStyle & RoundStyle.Top;
                    break;
                case CaptionStyle.Left:
                    gradientMode = LinearGradientMode.Horizontal;
                    roundStyle = RoundStyle & RoundStyle.Left;
                    break;
                case CaptionStyle.Bottom:
                    roundStyle = RoundStyle & RoundStyle.Bottom;
                    break;
                case CaptionStyle.Right:
                    gradientMode = LinearGradientMode.Horizontal;
                    roundStyle = RoundStyle & RoundStyle.Right;
                    break;
            }

            if (!_showBorder)
            {
                roundStyle = RoundStyle.All;
            }

            using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
            {
                RenderHelper.RenderBackgroundInternal(
                    g,
                    captionRect,
                    ColorTable.CaptionBackNormal,
                    ColorTable.Border,
                    Color.White,
                    roundStyle,
                    Radius,
                    true,
                    true,
                    gradientMode);
            }

            RenderImageAndText(g, captionRect);

            RenderBorder(g, base.ClientRectangle);
        }
예제 #6
0
        private void RenderImageAndText(Graphics g, Rectangle captionRect)
        {
            Rectangle imageRect  = Rectangle.Empty;
            Rectangle textRect   = Rectangle.Empty;
            int       bordWidth  = base.BorderWidth;
            int       imageWidth = CaptionHeight - 6;

            StringFormat sf = new StringFormat();

            sf.FormatFlags = StringFormatFlags.NoWrap;
            sf.Trimming    = StringTrimming.EllipsisCharacter;

            bool rightToLeft = base.RightToLeft == RightToLeft.Yes;
            bool drawImage   = Owner.ImageStyle == CaptionImageStyle.Draw ||
                               Owner.ImageStyle == CaptionImageStyle.Image;

            if (rightToLeft)
            {
                sf.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
            }

            if (drawImage)
            {
                imageRect = new Rectangle(
                    bordWidth, captionRect.Y + 3, imageWidth, imageWidth);
            }
            else
            {
                imageRect.X = bordWidth - 3;
            }

            textRect = new Rectangle(
                imageRect.Right + 3,
                captionRect.Y,
                captionRect.Width - (imageRect.Right + 3) - bordWidth,
                captionRect.Height);

            if (rightToLeft)
            {
                imageRect.X = captionRect.Right - imageRect.Right;
                textRect.X  = captionRect.Right - textRect.Right;
            }

            sf.LineAlignment = StringAlignment.Center;

            switch (TextAlign)
            {
            case ContentAlignment.BottomCenter:
            case ContentAlignment.MiddleCenter:
            case ContentAlignment.TopCenter:
                sf.Alignment = StringAlignment.Center;
                break;

            case ContentAlignment.BottomLeft:
            case ContentAlignment.MiddleLeft:
            case ContentAlignment.TopLeft:
                sf.Alignment = StringAlignment.Near;
                break;

            case ContentAlignment.BottomRight:
            case ContentAlignment.MiddleRight:
            case ContentAlignment.TopRight:
                sf.Alignment = StringAlignment.Far;
                break;
            }

            if (!string.IsNullOrEmpty(base.Text))
            {
                using (Brush brush = new SolidBrush(ColorTable.CaptionFore))
                {
                    g.DrawString(
                        base.Text,
                        CaptionFont,
                        brush,
                        textRect,
                        sf);
                }
            }

            if (drawImage)
            {
                if (Owner.ImageStyle == CaptionImageStyle.Image)
                {
                    Image image = _isExpanded ?
                                  Owner.ExpandImage : Owner.CollapseImage;
                    if (image != null)
                    {
                        g.DrawImage(
                            image,
                            imageRect,
                            0,
                            0,
                            image.Width,
                            image.Height,
                            GraphicsUnit.Pixel);
                    }
                }
                else
                {
                    ArrowDirection direction = _isExpanded ?
                                               ArrowDirection.Up : ArrowDirection.Down;
                    using (SmoothingModeGraphics sg = new SmoothingModeGraphics(g))
                    {
                        using (Brush brush = new SolidBrush(ColorTable.CaptionFore))
                        {
                            RenderHelper.RenderArrowInternal(
                                g,
                                imageRect,
                                direction,
                                brush);
                        }
                    }
                }
            }
        }
예제 #7
0
        protected virtual void WmNcPaint(ref Message m)
        {
            IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd);

            if (hDC == IntPtr.Zero)
            {
                return;
            }

            try
            {
                Rectangle bounds = new Rectangle(Point.Empty, base.Size);
                Rectangle client = base.ClientRectangle;
                client.X = _borderWidth;
                client.Y = _borderWidth;

                using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height))
                {
                    Win32.NativeMethods.ExcludeClipRect(
                        bufferedDC.Hdc,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    DrawTransparentBackground(
                        bufferedDC.Hdc,
                        bounds,
                        base.Location);

                    using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc))
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                            bounds, _radius, _roundStyle, true))
                        {
                            g.SetClip(path);
                        }
                        g.ExcludeClip(client);

                        if (base.BackgroundImage != null)
                        {
                            ControlPaintEx.DrawBackgroundImage(
                                g,
                                base.BackgroundImage,
                                base.BackColor,
                                base.BackgroundImageLayout,
                                bounds,
                                bounds);
                        }
                        else if (base.BackColor != Color.Transparent)
                        {
                            using (Brush brush = new SolidBrush(base.BackColor))
                            {
                                g.FillRectangle(brush, bounds);
                            }
                        }

                        g.ResetClip();

                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                            bounds, _radius, _roundStyle, true))
                        {
                            using ( SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g))
                            {
                                g.DrawPath(Pens.Black, path);
                            }
                        }
                    }

                   Win32.NativeMethods.ExcludeClipRect(
                        hDC,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    Win32.NativeMethods.BitBlt(
                        hDC,
                        bounds.X,
                        bounds.Y,
                        bounds.Width,
                        bounds.Height,
                        bufferedDC.Hdc,
                        0,
                        0,
                        TernaryRasterOperations.SRCCOPY);
                }
            }
            catch
            {
            }
            finally
            {
                Win32.NativeMethods.ReleaseDC(m.HWnd, hDC);
            }
        }
예제 #8
0
파일: NCPanel.cs 프로젝트: icprog/MaTuo
        protected virtual void WmNcPaint(ref Message m)
        {
            IntPtr hDC = Win32.NativeMethods.GetWindowDC(m.HWnd);

            if (hDC == IntPtr.Zero)
            {
                return;
            }

            try
            {
                Rectangle bounds = new Rectangle(Point.Empty, base.Size);
                Rectangle client = base.ClientRectangle;
                client.X = _borderWidth;
                client.Y = _borderWidth;

                using (ImageDc bufferedDC = new ImageDc(base.Width, base.Height))
                {
                    Win32.NativeMethods.ExcludeClipRect(
                        bufferedDC.Hdc,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    DrawTransparentBackground(
                        bufferedDC.Hdc,
                        bounds,
                        base.Location);

                    using (Graphics g = Graphics.FromHdc(bufferedDC.Hdc))
                    {
                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                                   bounds, _radius, _roundStyle, true))
                        {
                            g.SetClip(path);
                        }
                        g.ExcludeClip(client);

                        if (base.BackgroundImage != null)
                        {
                            ControlPaintEx.DrawBackgroundImage(
                                g,
                                base.BackgroundImage,
                                base.BackColor,
                                base.BackgroundImageLayout,
                                bounds,
                                bounds);
                        }
                        else if (base.BackColor != Color.Transparent)
                        {
                            using (Brush brush = new SolidBrush(base.BackColor))
                            {
                                g.FillRectangle(brush, bounds);
                            }
                        }

                        g.ResetClip();

                        using (GraphicsPath path = GraphicsPathHelper.CreatePath(
                                   bounds, _radius, _roundStyle, true))
                        {
                            using (SmoothingModeGraphics antiGraphics = new SmoothingModeGraphics(g))
                            {
                                g.DrawPath(Pens.Black, path);
                            }
                        }
                    }

                    Win32.NativeMethods.ExcludeClipRect(
                        hDC,
                        client.Left,
                        client.Top,
                        client.Right,
                        client.Bottom);

                    Win32.NativeMethods.BitBlt(
                        hDC,
                        bounds.X,
                        bounds.Y,
                        bounds.Width,
                        bounds.Height,
                        bufferedDC.Hdc,
                        0,
                        0,
                        TernaryRasterOperations.SRCCOPY);
                }
            }
            catch
            {
            }
            finally
            {
                Win32.NativeMethods.ReleaseDC(m.HWnd, hDC);
            }
        }