Exemplo n.º 1
0
 private void DrawMenuItemBar(Graphics g, DrawItemEventArgs e, Rectangle rect, bool rightToLeft)
 {
     using (var brush = StiBrushes.GetControlBrush(rect, 0f))
     {
         g.FillRectangle(brush, rect);
     }
 }
        protected override void OnPaint(PaintEventArgs p)
        {
            var g    = p.Graphics;
            var rect = new Rectangle(0, 0, Width, Height);

            if (BackgroundImage == null)
            {
                if (ControlStyle == StiControlStyle.Office2013Blue)
                {
                    using (var brush = new SolidBrush(Color.White))
                    {
                        g.FillRectangle(brush, rect);
                    }
                }
                else if (ControlStyle == StiControlStyle.Office2010)
                {
                    using (var brush = new SolidBrush(Color.FromArgb(245, 245, 245)))
                    {
                        g.FillRectangle(brush, rect);
                    }
                }
                else
                {
                    using (var brush = StiBrushes.GetControlBrush(rect, 90))
                    {
                        g.FillRectangle(brush, rect);
                    }
                }
            }
            else
            {
                StiControlPaint.DrawImageBackground(g, BackgroundImage, rect);
            }

            using (var penDark = new Pen(StiColorUtils.Dark(SystemColors.Control, 30)))
            {
                if (ControlStyle == StiControlStyle.Office2013Blue || ControlStyle == StiControlStyle.Office2010)
                {
                    penDark.Color       = Color.FromArgb(198, 198, 198);
                    penDark.DashPattern = new float[] { 1f, 2f };

                    if (lineStyle == StiToolBarLineStyle.Bottom)
                    {
                        g.DrawLine(penDark, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                    }
                    else if (lineStyle == StiToolBarLineStyle.All)
                    {
                        g.DrawRectangle(penDark, rect.X, rect.Y, rect.Right - 1, rect.Bottom - 1);
                    }
                    else
                    {
                        g.DrawLine(penDark, rect.X, rect.Top, rect.Right - 1, rect.Top);
                        g.DrawLine(penDark, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                    }
                }
                else
                {
                    g.DrawLine(penDark, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
                    g.DrawLine(penDark, rect.Right - 1, rect.Bottom - 1, rect.Right - 1, rect.Y);
                }
            }

            if (ControlStyle == StiControlStyle.Flat)
            {
                int y = (Height - 16) / 2;
                int x = 4;
                if (this.RightToLeft == RightToLeft.Yes)
                {
                    x = this.Width - 6;
                }
                DrawDot(g, x, y);
                DrawDot(g, x, y + 4);
                DrawDot(g, x, y + 8);
                DrawDot(g, x, y + 12);
            }
        }
Exemplo n.º 3
0
        private void DrawPage(Graphics g, StiTabPage page)
        {
            if ((!page.Invisible) || DesignMode)
            {
                var rect = GetPageRectangle(g, page);

                if (rect.Width != 0 && rect.Height != 0)
                {
                    #region Calculate Path

                    var pts = new Point [] {};

                    #region Office2013
                    if (ControlStyle == StiControlStyle.Office2013Blue)
                    {
                        pts = new Point[] {
                            new Point(rect.X, rect.Y),
                            new Point(rect.X, rect.Bottom),
                            new Point(rect.Right, rect.Bottom),
                            new Point(rect.Right, rect.Y)
                        };
                    }
                    #endregion

                    #region Flat
                    else
                    {
                        if (!PositionAtBottom)
                        {
                            pts = new Point[] {
                                new Point(rect.X, rect.Y),
                                new Point(rect.X, rect.Bottom),
                                new Point(rect.Right + 5, rect.Bottom),
                                new Point(rect.Right - 5, rect.Y)
                            };
                        }
                        else
                        {
                            pts = new Point[] {
                                new Point(rect.X, rect.Y),
                                new Point(rect.X, rect.Bottom),
                                new Point(rect.Right - 5, rect.Bottom),
                                new Point(rect.Right + 5, rect.Y)
                            };
                        }
                    }
                    #endregion

                    #endregion


                    using (var path = new GraphicsPath(FillMode.Alternate))
                    {
                        path.AddPolygon(pts);

                        #region Draw page header

                        #region Office2013
                        if (ControlStyle == StiControlStyle.Office2013Blue)
                        {
                            if (SelectedTab == page)
                            {
                                using (var pathSelected = new GraphicsPath())
                                {
                                    pathSelected.AddPolygon(new[] {
                                        new Point(pts[0].X - 1, pts[0].Y - 1),
                                        new Point(pts[1].X - 1, pts[1].Y),
                                        new Point(pts[2].X + 1, pts[2].Y),
                                        new Point(pts[3].X + 1, pts[3].Y)
                                    });

                                    using (var br = new SolidBrush(Color.White))
                                    {
                                        g.FillPath(br, pathSelected);
                                    }
                                }
                            }
                            else
                            {
                                using (var br = new SolidBrush(Color.White))
                                {
                                    g.FillPath(br, path);
                                }
                            }
                        }
                        #endregion

                        #region Flat
                        else
                        {
                            if (SelectedTab == page)
                            {
                                var tabPage = GetTabPageAtPoint(this.PointToClient(Cursor.Position));
                                if (tabPage == page)
                                {
                                    using (var br = StiBrushes.GetControlLightBrush(rect, 90))
                                    {
                                        g.FillPath(br, path);
                                    }
                                }
                                else
                                {
                                    using (var br = StiBrushes.GetControlBrush(rect, 90))
                                    {
                                        g.FillPath(br, path);
                                    }
                                }
                            }
                            else
                            {
                                var tabPage = GetTabPageAtPoint(this.PointToClient(Cursor.Position));
                                if (tabPage == page)
                                {
                                    using (var br = new SolidBrush(StiColorUtils.Light(StiColors.Content, 15)))
                                    {
                                        g.FillPath(br, path);
                                    }
                                }
                                else
                                {
                                    g.FillPath(StiBrushes.Content, path);
                                }
                            }
                        }
                        #endregion

                        #endregion
                    }


                    Color textColor = ForeColor;
                    if (page != this.SelectedTab)
                    {
                        textColor = SystemColors.ControlDark;
                    }


                    #region Paint Image
                    SizeF imageSize = SizeF.Empty;
                    if (ImageList != null || page.Image != null)
                    {
                        int pageIndex = this.Controls.IndexOf(page);

                        if (ImageList != null || page.Image != null)
                        {
                            if (page.Image != null)
                            {
                                imageSize = page.Image.Size;
                            }
                            else
                            {
                                imageSize = ImageList.ImageSize;
                            }

                            Rectangle imageRect = new Rectangle(rect.X + 2,
                                                                (int)(rect.Y + (rect.Height - imageSize.Height) / 2),
                                                                (int)imageSize.Width, (int)imageSize.Height);

                            if (imageSize.Width != 0)
                            {
                                if (imageList != null && ImageList.Images.Count > pageIndex)
                                {
                                    ImageList.Draw(g, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height, pageIndex);
                                }
                                else if (page.Image != null)
                                {
                                    g.DrawImage(page.Image, imageRect.X, imageRect.Y, imageRect.Width, imageRect.Height);
                                }
                            }
                        }
                    }
                    #endregion

                    #region Paint text
                    var textRect = new Rectangle(rect.X + (int)imageSize.Width, rect.Y, rect.Width - (int)imageSize.Width, rect.Height);
                    using (var brush = new SolidBrush(textColor))
                    {
                        g.DrawString(page.Text, Font, brush, textRect, sfTabs);
                    }
                    #endregion

                    #region Draw header lines

                    #region Office2013 Style
                    if (ControlStyle == StiControlStyle.Office2013Blue)
                    {
                        using (var pen = new Pen(StiStyleOffice2013Blue.ColorLineGray))
                        {
                            if (SelectedTab == page)
                            {
                                if (!PositionAtBottom)
                                {
                                    g.DrawLine(pen, new Point(pts[0].X - 1, pts[0].Y - 1), new Point(pts[1].X - 1, pts[1].Y));
                                    g.DrawLine(pen, new Point(pts[0].X - 1, pts[0].Y - 1), new Point(pts[3].X + 1, pts[3].Y - 1));
                                    g.DrawLine(pen, new Point(pts[2].X + 1, pts[2].Y), new Point(pts[3].X + 1, pts[3].Y));
                                }
                                else
                                {
                                    g.DrawLine(pen, pts[1], pts[2]);
                                    g.DrawLine(pen, pts[2], pts[3]);
                                }
                            }
                            else
                            {
                                if (PositionAtBottom)
                                {
                                    g.DrawLine(pen, pts[0], pts[1]);
                                    g.DrawLine(pen, pts[1], pts[2]);
                                    g.DrawLine(pen, pts[2], pts[3]);
                                }
                                else
                                {
                                    g.DrawLine(pen, pts[0], pts[1]);
                                    g.DrawLine(pen, pts[0], pts[3]);
                                    g.DrawLine(pen, pts[2], pts[3]);
                                }
                            }
                        }
                    }
                    #endregion

                    #region Flat Style
                    else
                    {
                        if (SelectedTab == page)
                        {
                            g.DrawLine(SystemPens.ControlLightLight, pts[0], pts[1]);

                            if (!PositionAtBottom)
                            {
                                using (var brush = new LinearGradientBrush(
                                           new Rectangle(pts[3].X, pts[3].Y, pts[2].X - pts[3].X, pts[2].Y - pts[3].Y - 5),
                                           SystemColors.Control, SystemColors.ControlDark, 0f))

                                    using (var pen = new Pen(brush))
                                        g.DrawLine(pen, pts[2], pts[3]);

                                g.DrawLine(SystemPens.ControlLightLight, pts[0], pts[3]);
                            }
                            else
                            {
                                g.DrawLine(SystemPens.ControlDark, pts[1], pts[2]);
                                g.DrawLine(SystemPens.ControlDark, pts[2], pts[3]);
                            }
                        }
                        else
                        {
                            using (var pen = new Pen(StiColorUtils.Dark(SystemColors.Control, 40)))
                            {
                                if (PositionAtBottom)
                                {
                                    g.DrawLine(pen, pts[0], pts[1]);
                                    g.DrawLine(pen, pts[1], pts[2]);
                                    g.DrawLine(pen, pts[2], pts[3]);
                                }
                                else
                                {
                                    g.DrawLine(pen, pts[0], pts[1]);
                                    g.DrawLine(pen, pts[0], pts[3]);
                                    g.DrawLine(pen, pts[2], pts[3]);
                                }
                            }
                        }
                    }
                    #endregion

                    #endregion
                }
            }
        }