private void DrawButton(Graphics e, mcButtonState state, mcHeaderButtons button, Rectangle rect)
        {
            Bitmap image = null;
            int    x     = 0;
            int    y     = 0;
            int    corr  = 0;

            if (Application.RenderWithVisualStyles)
            {
                VisualStyleElement element = VisualStyleElement.Button.PushButton.Normal;

                if (m_calendar.Enabled)
                {
                    if (state == mcButtonState.Hot)
                    {
                        element = VisualStyleElement.Button.PushButton.Hot;
                    }
                    else if (state == mcButtonState.Inactive)
                    {
                        element = VisualStyleElement.Button.PushButton.Disabled;
                    }
                    else if (state == mcButtonState.Pushed)
                    {
                        element = VisualStyleElement.Button.PushButton.Pressed;
                    }
                }
                else
                {
                    element = VisualStyleElement.Button.PushButton.Disabled;
                }

                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(e, rect);
                switch (button)
                {
                case mcHeaderButtons.PreviousMonth:
                {
                    image = m_prevMonthVs;
                    x     = rect.Left + 5;
                    y     = rect.Top + 5;
                    break;
                }

                case mcHeaderButtons.PreviousYear:
                {
                    image = m_prevYearVs;
                    x     = rect.Left + 4;
                    y     = rect.Top + 5;
                    break;
                }

                case mcHeaderButtons.NextMonth:
                {
                    image = m_nextMonthVs;
                    x     = rect.Right - 13;
                    y     = rect.Top + 5;
                    break;
                }

                case mcHeaderButtons.NextYear:
                {
                    image = m_nextYearVs;
                    x     = rect.Right - 16;
                    y     = rect.Top + 5;
                    break;
                }
                }

                if ((m_calendar.Enabled) && (state != mcButtonState.Inactive))
                {
                    e.DrawImageUnscaled(image, new Point(x, y));
                }
                else
                {
                    ControlPaint.DrawImageDisabled(e, image, x, y, Color.Transparent);
                }
            }
            else
            {
                ButtonState btnState = ButtonState.Normal;
                if (m_calendar.Enabled)
                {
                    if (state == mcButtonState.Hot)
                    {
                        btnState = ButtonState.Normal;
                    }
                    else if (state == mcButtonState.Inactive)
                    {
                        btnState = ButtonState.Inactive;
                    }
                    else if (state == mcButtonState.Pushed)
                    {
                        btnState = ButtonState.Pushed;
                    }
                }
                else
                {
                    btnState = ButtonState.Inactive;
                }

                switch (button)
                {
                case mcHeaderButtons.PreviousMonth:
                {
                    ControlPaint.DrawScrollButton(e, rect, ScrollButton.Left, btnState);
                    break;
                }

                case mcHeaderButtons.NextMonth:
                {
                    ControlPaint.DrawScrollButton(e, rect, ScrollButton.Right, btnState);
                    break;
                }

                case mcHeaderButtons.NextYear:
                {
                    ControlPaint.DrawButton(e, rect, btnState);
                    if (state == mcButtonState.Pushed)
                    {
                        corr = 1;
                    }
                    if ((m_calendar.Enabled) && (m_nextYearBtnState != mcButtonState.Inactive))
                    {
                        e.DrawImage(m_nextYear, new Point(rect.Left + 3, rect.Top + 2 + corr));
                    }
                    else
                    {
                        e.DrawImage(m_nextYearDisabled, new Point(rect.Left + 3, rect.Top + 2 + corr));
                    }

                    break;
                }

                case mcHeaderButtons.PreviousYear:
                {
                    ControlPaint.DrawButton(e, rect, btnState);
                    if (state == mcButtonState.Pushed)
                    {
                        corr = 1;
                    }
                    if ((m_calendar.Enabled) && (m_prevYearBtnState != mcButtonState.Inactive))
                    {
                        e.DrawImage(m_prevYear, new Point(rect.Left, rect.Top + 2 + corr));
                    }
                    else
                    {
                        e.DrawImage(m_prevYearDisabled, new Point(rect.Left, rect.Top + 2 + corr));
                    }

                    break;
                }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Raises the <see cref="E:Paint" /> event.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs"/> instance containing the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(VisualStyleElement.CreateElement("TaskDialog", 8, 0)))
            {
                PaintWithVisualStyles(e.Graphics);
            }
            else
            {
                PaintManually(e.Graphics);
            }

            base.OnPaint(e);
        }
Example #3
0
        protected override void OnDrawColumnHeader(DrawListViewColumnHeaderEventArgs e)
        {
            #if DEFAULT_HEADER
            e.DrawDefault = true;
            #else
            using (var sf = new StringFormat())
            {
                Graphics  gfx = e.Graphics;
                Rectangle rt  = e.Bounds;

                #if !__MonoCS__
                VisualStyleElement element = VisualStyleElement.Header.Item.Normal;
                if ((e.State & ListViewItemStates.Hot) == ListViewItemStates.Hot)
                {
                    element = VisualStyleElement.Header.Item.Hot;
                }
                if ((e.State & ListViewItemStates.Selected) == ListViewItemStates.Selected)
                {
                    element = VisualStyleElement.Header.Item.Pressed;
                }

                var visualStyleRenderer = new VisualStyleRenderer(element);
                visualStyleRenderer.DrawBackground(gfx, rt);
                #else
                e.DrawBackground();
                #endif

                switch (e.Header.TextAlign)
                {
                case HorizontalAlignment.Left:
                    sf.Alignment = StringAlignment.Near;
                    break;

                case HorizontalAlignment.Right:
                    sf.Alignment = StringAlignment.Far;
                    break;

                case HorizontalAlignment.Center:
                    sf.Alignment = StringAlignment.Center;
                    break;
                }

                sf.LineAlignment = StringAlignment.Center;
                sf.Trimming      = StringTrimming.EllipsisCharacter;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                int w = TextRenderer.MeasureText(" ", Font).Width;
                rt.Inflate(-(w / 5), 0);

                gfx.DrawString(e.Header.Text, Font, Brushes.Black, rt, sf);

                string arrow = "";
                switch (GetColumnSortOrder(e.ColumnIndex))
                {
                case SortOrder.Ascending:
                    arrow = "▲";
                    break;

                case SortOrder.Descending:
                    arrow = "▼";
                    break;
                }

                if (arrow != "")
                {
                    using (var fnt = new Font(Font.FontFamily, Font.SizeInPoints * 0.6f, FontStyle.Regular)) {
                        float aw = gfx.MeasureString(arrow, fnt).Width;
                        float x  = rt.Left + (rt.Width - aw) / 2.0f;
                        gfx.TextRenderingHint = TextRenderingHint.AntiAlias;
                        gfx.DrawString(arrow, fnt, Brushes.Black, x, rt.Top);
                    }
                }
            }
            #endif

            base.OnDrawColumnHeader(e);
        }
Example #4
0
        private void RenderSeparatorInternal1(Graphics g, ToolStripItem item, Rectangle bounds, bool vertical)
        {
            VisualStyleElement separator = vertical ? VisualStyleElement.ToolBar.SeparatorHorizontal.Normal : VisualStyleElement.ToolBar.SeparatorVertical.Normal;

            if (ToolStripManager.VisualStylesEnabled && (VisualStyleRenderer.IsElementDefined(separator)))
            {
                VisualStyleRenderer visualStyleRenderer = new VisualStyleRenderer("ExplorerBar", 0, 0);

                visualStyleRenderer.SetParameters(separator.ClassName, separator.Part, 1);                 //GetItemState(item))
                visualStyleRenderer.DrawBackground(g, bounds);
            }
            else
            {
                Color foreColor = item.ForeColor;
                Color backColor = item.BackColor;

                Pen  foreColorPen        = SystemPens.ControlDark;
                bool disposeForeColorPen = GetPen(foreColor, ref foreColorPen);

                try {
                    if (vertical)
                    {
                        if (bounds.Height >= 4)                           // scoot down 2PX and start drawing
                        {
                            bounds.Inflate(0, -2);
                        }

                        bool rightToLeft = (item.RightToLeft == RightToLeft.Yes);
                        Pen  leftPen     = rightToLeft ? SystemPens.ButtonHighlight : foreColorPen;
                        Pen  rightPen    = rightToLeft ? foreColorPen : SystemPens.ButtonHighlight;

                        // Draw dark line
                        int startX = bounds.Width / 2;
                        g.DrawLine(leftPen, startX, bounds.Top, startX, bounds.Bottom);

                        // Draw highlight one pixel to the right
                        startX += 1;
                        g.DrawLine(rightPen, startX, bounds.Top, startX, bounds.Bottom);
                    }
                    else
                    {
                        //
                        // horizontal separator
                        if (bounds.Width >= 4)                           // scoot over 2PX and start drawing
                        {
                            bounds.Inflate(-2, 0);
                        }

                        // Draw dark line
                        int startY = bounds.Height / 2;
                        g.DrawLine(foreColorPen, bounds.Left, startY, bounds.Right, startY);

                        // Draw highlight one pixel to the right
                        startY += 1;
                        g.DrawLine(SystemPens.ButtonHighlight, bounds.Left, startY, bounds.Right, startY);
                    }
                } finally {
                    if (disposeForeColorPen && foreColorPen != null)
                    {
                        foreColorPen.Dispose();
                    }
                }
            }
        }
 public ManagedStyleRenderer(VisualStyleElement styleElement)
 {
     _renderer = new VisualStyleRenderer(styleElement);
 }
Example #6
0
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            Graphics       g    = e.Graphics;
            TabStrip       tabs = e.ToolStrip as TabStrip;
            TabStripButton tab  = e.Item as TabStripButton;

            if (tabs == null || tab == null)
            {
                if (currentRenderer != null)
                {
                    currentRenderer.DrawButtonBackground(e);
                }
                else
                {
                    base.OnRenderButtonBackground(e);
                }
                return;
            }

            bool      selected = tab.Checked;
            bool      hovered  = tab.Selected;
            int       top      = 0;
            int       left     = 0;
            int       width    = tab.Bounds.Width - 1;
            int       height   = tab.Bounds.Height - 1;
            Rectangle drawBorder;


            if (UseVS)
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    drawBorder = new Rectangle(0, 0, width, height);
                }
                else
                {
                    if (!selected)
                    {
                        left   = selOffset;
                        width -= (selOffset - 1);
                    }
                    else
                    {
                        left = 1;
                    }
                    drawBorder = new Rectangle(0, 0, height, width);
                }
                using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height))
                {
                    VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal;
                    if (selected)
                    {
                        el = VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (hovered)
                    {
                        el = VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!tab.Enabled)
                    {
                        el = VisualStyleElement.Tab.TabItem.Disabled;
                    }

                    if (!selected || hovered)
                    {
                        drawBorder.Width++;
                    }
                    else
                    {
                        drawBorder.Height++;
                    }

                    using (Graphics gr = Graphics.FromImage(b))
                    {
                        VisualStyleRenderer rndr = new VisualStyleRenderer(el);
                        rndr.DrawBackground(gr, drawBorder);

                        if (tabs.Orientation == Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipXY);
                            }
                            else
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            }
                        }
                        if (Mirrored)
                        {
                            left = tab.Bounds.Width - b.Width - left;
                            top  = tab.Bounds.Height - b.Height - top;
                        }
                        g.DrawImage(b, left, top);
                    }
                }
            }
            else
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    if (Mirrored)
                    {
                        left = 1;
                        top  = 0;
                    }
                    else
                    {
                        top++;
                    }
                    width--;
                }
                else
                {
                    if (!selected)
                    {
                        left = selOffset;
                        width--;
                    }
                    else
                    {
                        left = 1;
                    }
                    if (Mirrored)
                    {
                        left = 0;
                        top  = 1;
                    }
                }
                height--;
                drawBorder = new Rectangle(left, top, width, height);

                using (GraphicsPath gp = new GraphicsPath())
                {
                    if (Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top);
                    }
                    else if (!Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom);
                    }
                    else if (Mirrored && tabs.Orientation == Orientation.Vertical)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom);
                    }
                    else
                    {
                        gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom);
                    }

                    if (selected || hovered)
                    {
                        Color fill = (hovered) ? Color.WhiteSmoke : Color.White;
                        if (renderMode == ToolStripRenderMode.Professional)
                        {
                            fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd;
                            using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical))
                                g.FillPath(br, gp);
                        }
                        else
                        {
                            using (SolidBrush br = new SolidBrush(fill))
                                g.FillPath(br, gp);
                        }
                    }
                    using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace))
                        g.DrawPath(p, gp);
                }
            }
        }
Example #7
0
        public Toast(Account account)
        {
            InitializeComponent();

            this.Account = account;

            this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);

            this.UpdateStyles();

            if (!VisualStyleRenderer.IsSupported)
            {
                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
                this.ControlBox      = true;
                this.Icon            = Program.MainForm.Icon;
            }

            int enabled  = 0;
            int response = DwmIsCompositionEnabled(ref enabled);

            _aeroEnabled = enabled == 1;

            this.Opacity = 0;
            //this.TopMost = true;
            SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, SetWindowPosFlags.NOACTIVATE | SetWindowPosFlags.NOSIZE | SetWindowPosFlags.NOREPOSITION);

            _closeTimer.Tick += delegate(object sender, EventArgs e) {
                this.Close();
            };

            _elementClose = VisualStyleElement.Window.SmallCloseButton.Normal;
            _elementPrev  = VisualStyleElement.CreateElement("TaskbandExtendedUI", LeftControl, 1);
            _elementInbox = VisualStyleElement.CreateElement("TaskbandExtendedUI", CenterControl, 1);
            _elementNext  = VisualStyleElement.CreateElement("TaskbandExtendedUI", RightControl, 1);

            _iconPrev   = Resources.Icons.Previous;       // ResourceHelper.GetIcon("Previous.ico");
            _iconInbox  = Resources.Icons.Inbox;          // ResourceHelper.GetIcon("Inbox.ico");
            _iconNext   = Resources.Icons.Next;           // ResourceHelper.GetIcon("Next.ico");
            _iconWindow = Resources.Icons.Window;         // ResourceHelper.GetIcon("gmail-classic.ico", 16);

            ToolTip openTip = new ToolTip();

            openTip.SetToolTip(_PictureOpen, Localization.Locale.Current.Toast.ViewEmail);

            _PictureOpen.Cursor = Cursors.Hand;
            _PictureOpen.Click += OpenEmail;

            //using (Icon icon = ResourceHelper.GetIcon("Open.ico")) {
            //  _PictureOpen.Image = icon.ToBitmap();
            //}

            _PictureOpen.Image = Resources.Icons.Open.ToBitmap();

            if (this.Account.Emails.Count > 1)
            {
                _stateNext = State.Normal;
            }

            // show the last (newest) email
            _mailIndex = 0;             //this.Account.Emails.Count - 1;

            UpdateBody();
        }
 // Constructors
 public VisualStyleRenderer(VisualStyleElement element)
 {
 }
Example #9
0
 private VisualStyleElement Subclass(VisualStyleElement element)
 {
     return VisualStyleElement.CreateElement(SubclassPrefix + element.ClassName,
             element.Part, element.State);
 }
Example #10
0
 private VisualStyleElement Subclass(VisualStyleElement element)
 {
     return(VisualStyleElement.CreateElement(SubclassPrefix + element.ClassName,
                                             element.Part, element.State));
 }
Example #11
0
 protected override void OnDrawNode(DrawTreeNodeEventArgs e)
 {
     if (e.Node.Nodes.Count == 0)
     {
         e.DrawDefault = true;
     }
     else if (VisualStyleRenderer.IsSupported)
     {
         SizeF     ef     = e.Graphics.MeasureString(e.Node.Text, this.Font);
         int       x      = (((e.Bounds.X + 5) + (e.Node.Level * 0x13)) + 0x12) + 0x10;
         int       y      = e.Bounds.Y;
         Rectangle bounds = new Rectangle(x, y, (int)ef.Width, (int)ef.Height);
         TextRenderer.DrawText(e.Graphics, e.Node.Text, this.Font, bounds, this.ForeColor);
         Pen pen = new Pen(SystemColors.GrayText)
         {
             DashStyle = DashStyle.Dot
         };
         int num2 = e.Bounds.Height / 2;
         x -= 0x10;
         e.Graphics.DrawLine(pen, new Point(x, y + num2), new Point(x + 0x10, y + num2));
         if ((e.Node.Nodes.Count > 0) && e.Node.IsExpanded)
         {
             e.Graphics.DrawLine(pen, new Point(x + 8, y + num2), new Point(x + 8, y + e.Bounds.Height));
         }
         x -= 8;
         e.Graphics.DrawLine(pen, new Point(x, y + num2), new Point(x + 8, y + num2));
         x -= 10;
         e.Graphics.DrawLine(pen, new Point(x + 5, y + num2), new Point(x + 10, y + num2));
         int num3 = y + e.Bounds.Height;
         if (e.Node.NextNode == null)
         {
             num3 = y + num2;
         }
         e.Graphics.DrawLine(pen, new Point(x + 7, y), new Point(x + 7, num3));
         VisualStyleElement opened = null;
         if (e.Node.Nodes.Count > 0)
         {
             if (e.Node.IsExpanded)
             {
                 opened = VisualStyleElement.TreeView.Glyph.Opened;
             }
             else
             {
                 opened = VisualStyleElement.TreeView.Glyph.Closed;
             }
         }
         Rectangle           rectangle8 = new Rectangle(x, y, 0x10, 0x10);
         VisualStyleRenderer renderer   = new VisualStyleRenderer(opened);
         if (e.Node.Nodes.Count > 0)
         {
             renderer.DrawBackground(e.Graphics, rectangle8);
         }
         TreeNode parent = e.Node;
         while (parent.Parent != null)
         {
             parent = parent.Parent;
             x     -= 0x13;
             if (parent.IsExpanded && (parent.NextNode != null))
             {
                 e.Graphics.DrawLine(pen, new Point(x + 7, y), new Point(x + 7, y + e.Bounds.Height));
             }
         }
     }
 }
Example #12
0
        private void PaintPriv(PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            if (g == null)
            {
                base.OnPaint(e); return;
            }

            int nNormPos = m_nPosition - m_nMinimum;
            int nNormMax = m_nMaximum - m_nMinimum;

            if (nNormMax <= 0)
            {
                Debug.Assert(false); nNormMax = 100;
            }
            if (nNormPos < 0)
            {
                Debug.Assert(false); nNormPos = 0;
            }
            if (nNormPos > nNormMax)
            {
                Debug.Assert(false); nNormPos = nNormMax;
            }

            Rectangle          rectClient = this.ClientRectangle;
            Rectangle          rectDraw;
            VisualStyleElement vse = VisualStyleElement.ProgressBar.Bar.Normal;

            if (VisualStyleRenderer.IsSupported &&
                VisualStyleRenderer.IsElementDefined(vse))
            {
                VisualStyleRenderer vsr = new VisualStyleRenderer(vse);

                if (vsr.IsBackgroundPartiallyTransparent())
                {
                    vsr.DrawParentBackground(g, rectClient, this);
                }

                vsr.DrawBackground(g, rectClient);

                rectDraw = vsr.GetBackgroundContentRectangle(g, rectClient);
            }
            else
            {
                g.FillRectangle(SystemBrushes.Control, rectClient);

                Pen penGray  = SystemPens.ControlDark;
                Pen penWhite = SystemPens.ControlLight;
                g.DrawLine(penGray, 0, 0, rectClient.Width - 1, 0);
                g.DrawLine(penGray, 0, 0, 0, rectClient.Height - 1);
                g.DrawLine(penWhite, rectClient.Width - 1, 0,
                           rectClient.Width - 1, rectClient.Height - 1);
                g.DrawLine(penWhite, 0, rectClient.Height - 1,
                           rectClient.Width - 1, rectClient.Height - 1);

                rectDraw = new Rectangle(rectClient.X + 1, rectClient.Y + 1,
                                         rectClient.Width - 2, rectClient.Height - 2);
            }

            int nDrawWidth = (int)((float)rectDraw.Width * (float)nNormPos /
                                   (float)nNormMax);

            Color clrStart = Color.FromArgb(255, 128, 0);
            Color clrEnd   = Color.FromArgb(0, 255, 0);

            if (!this.Enabled)
            {
                clrStart = UIUtil.ColorToGrayscale(SystemColors.ControlDark);
                clrEnd   = UIUtil.ColorToGrayscale(SystemColors.ControlLight);
            }

            bool bRtl = (this.RightToLeft == RightToLeft.Yes);

            if (bRtl)
            {
                Color clrTemp = clrStart;
                clrStart = clrEnd;
                clrEnd   = clrTemp;
            }

            // Workaround for Windows <= XP
            Rectangle rectGrad = new Rectangle(rectDraw.X, rectDraw.Y,
                                               rectDraw.Width, rectDraw.Height);

            if (!WinUtil.IsAtLeastWindowsVista && !NativeLib.IsUnix())
            {
                rectGrad.Inflate(1, 0);
            }

            using (LinearGradientBrush brush = new LinearGradientBrush(rectGrad,
                                                                       clrStart, clrEnd, LinearGradientMode.Horizontal))
            {
                g.FillRectangle(brush, (bRtl ? (rectDraw.Width - nDrawWidth + 1) :
                                        rectDraw.Left), rectDraw.Top, nDrawWidth, rectDraw.Height);
            }

            PaintText(g, rectDraw);
        }
Example #13
0
        public static void DrawCommandButton(
            Graphics g,
            PushButtonState state,
            Rectangle rect,
            Color backColor,
            Control childControl)
        {
            VisualStyleElement element = null;
            int alpha = 255;

            if (Environment.OSVersion.Version.Major >= 6)
            {
                const string className = "BUTTON";
                const int    partID    = NativeConstants.BP_COMMANDLINK;
                int          stateID;

                switch (state)
                {
                case PushButtonState.Default:
                    stateID = NativeConstants.CMDLS_DEFAULTED;
                    break;

                case PushButtonState.Disabled:
                    stateID = NativeConstants.CMDLS_DISABLED;
                    break;

                case PushButtonState.Hot:
                    stateID = NativeConstants.CMDLS_HOT;
                    break;

                case PushButtonState.Normal:
                    stateID = NativeConstants.CMDLS_NORMAL;
                    break;

                case PushButtonState.Pressed:
                    stateID = NativeConstants.CMDLS_PRESSED;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }

                try
                {
                    element = VisualStyleElement.CreateElement(className, partID, stateID);

                    if (!VisualStyleRenderer.IsElementDefined(element))
                    {
                        element = null;
                    }
                }
                catch (InvalidOperationException)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                switch (state)
                {
                case PushButtonState.Default:
                    element = VisualStyleElement.Button.PushButton.Default;
                    alpha   = 95;
                    break;

                case PushButtonState.Disabled:
                    element = VisualStyleElement.Button.PushButton.Disabled;
                    break;

                case PushButtonState.Hot:
                    element = VisualStyleElement.Button.PushButton.Hot;
                    break;

                case PushButtonState.Normal:
                    alpha   = 0;
                    element = VisualStyleElement.Button.PushButton.Normal;
                    break;

                case PushButtonState.Pressed:
                    element = VisualStyleElement.Button.PushButton.Pressed;
                    break;

                default:
                    throw new InvalidEnumArgumentException();
                }
            }

            if (element != null)
            {
                try
                {
                    VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                    renderer.DrawParentBackground(g, rect, childControl);
                    renderer.DrawBackground(g, rect);
                }
                catch (Exception)
                {
                    element = null;
                }
            }

            if (element == null)
            {
                ButtonRenderer.DrawButton(g, rect, state);
            }

            if (alpha != 255)
            {
                using (Brush backBrush = new SolidBrush(Color.FromArgb(255 - alpha, backColor)))
                {
                    CompositingMode oldCM = g.CompositingMode;

                    try
                    {
                        g.CompositingMode = CompositingMode.SourceOver;
                        g.FillRectangle(backBrush, rect);
                    }

                    finally
                    {
                        g.CompositingMode = oldCM;
                    }
                }
            }
        }
Example #14
0
 /// <summary>
 /// Notifies the DragDropHelper that the specified Window received
 /// a DragEnter event.
 /// </summary>
 /// <param name="window">The Window the received the DragEnter event.</param>
 /// <param name="data">The DataObject containing a drag image.</param>
 /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
 /// <param name="effect">The accepted drag drop effect.</param>
 public static void DragEnter(VisualStyleElement.Window window, IDataObject data, Point cursorOffset, DragDropEffects effect)
 {
     WpfDropTargetHelperExtensions.DragEnter(s_instance, window, data, cursorOffset, effect);
 }
Example #15
0
        private void _secondaryPanel_Paint(object sender, PaintEventArgs e)
        {
            VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.CreateElement("TASKDIALOG", 8, 0));

            renderer.DrawBackground(e.Graphics, _secondaryPanel.ClientRectangle, e.ClipRectangle);
        }
Example #16
0
 /// <summary>
 /// Notifies the DragDropHelper that the specified Window received
 /// a DragEnter event.
 /// </summary>
 /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
 /// <param name="window">The Window the received the DragEnter event.</param>
 /// <param name="data">The DataObject containing a drag image.</param>
 /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
 /// <param name="effect">The accepted drag drop effect.</param>
 public static void DragEnter(this IDropTargetHelper dropHelper, VisualStyleElement.Window window, IDataObject data, Point cursorOffset, DragDropEffects effect)
 {
     IntPtr windowHandle = IntPtr.Zero;
     if (window != null)
         windowHandle = (new WindowInteropHelper(window)).Handle;
     Win32Point pt = WpfDragDropLibExtensions.ToWin32Point(cursorOffset);
     dropHelper.DragEnter(windowHandle, (ComIDataObject)data, ref pt, (int)effect);
 }
Example #17
0
 public void VisualStyleRenderer_IsElementDefined_Invoke_ReturnsExpected(VisualStyleElement element, bool expected)
 {
     Assert.Equal(expected, VisualStyleRenderer.IsElementDefined(element));
 }
Example #18
0
    /// <summary>
    /// Generates a bitmap to display beside the ToolStripItem representation of the specified node.
    /// </summary>
    /// <param name="bitmapInfo"></param>
    /// <param name="nodeImage"></param>
    /// <returns></returns>
    private Image GenerateBitmap(BitmapInfo bitmapInfo, Image nodeImage)
    {
        int indentation = INDENT_WIDTH * bitmapInfo.NodeDepth;
        int halfIndent  = INDENT_WIDTH / 2;
        int halfHeight  = _itemHeight / 2;

        int bmpWidth = indentation;

        if (_nodeLinesNeeded)
        {
            bmpWidth += INDENT_WIDTH;
        }
        else
        {
            bmpWidth += 1;
        }

        if (_sourceControl.ShowCheckBoxes)
        {
            bmpWidth += 16;
        }
        else if (nodeImage != null)
        {
            bmpWidth += nodeImage.Width;
        }

        if (bmpWidth == 0)
        {
            return(null);
        }

        // create a bitmap that will be composed of the node's image and the glyphs/lines/indentation
        Bitmap composite = new Bitmap(bmpWidth, _itemHeight);

        using (Graphics g = Graphics.FromImage(composite)) {
            if (_nodeLinesNeeded)
            {
                using (Pen dotted = new Pen(Color.Gray)) {
                    dotted.DashStyle = DashStyle.Dot;

                    // horizontal dotted line
                    g.DrawLine(dotted, indentation + halfIndent, halfHeight, indentation + INDENT_WIDTH, halfHeight);

                    // vertical dotted line to peers
                    g.DrawLine(dotted, indentation + halfIndent, bitmapInfo.IsFirst ? halfHeight : 0, indentation + halfIndent, bitmapInfo.IsLastPeer ? halfHeight : _itemHeight);

                    // vertical dotted line to subtree
                    if (bitmapInfo.NodeExpanded)
                    {
                        g.DrawLine(dotted, INDENT_WIDTH + indentation + halfIndent, halfHeight, INDENT_WIDTH + indentation + halfIndent, _itemHeight);
                    }

                    // outer vertical dotted lines
                    for (int i = 0; i < bitmapInfo.VerticalLines.Length; i++)
                    {
                        if (bitmapInfo.VerticalLines[i])
                        {
                            int parentIndent = (INDENT_WIDTH * (bitmapInfo.NodeDepth - (i + 1)));
                            g.DrawLine(dotted, parentIndent + halfIndent, 0, parentIndent + halfIndent, _itemHeight);
                        }
                    }
                }
            }

            if (_sourceControl.ShowCheckBoxes)
            {
                // leave space for checkbox glyph
            }
            else if (nodeImage != null)
            {
                // composite the image associated with node (appears at far right)
                g.DrawImage(nodeImage, new Rectangle(
                                INDENT_WIDTH + indentation,
                                composite.Height / 2 - nodeImage.Height / 2,
                                nodeImage.Width,
                                nodeImage.Height
                                ));
            }

            // render plus/minus glyphs
            if (bitmapInfo.HasChildren)
            {
                Rectangle          glyphBounds = new Rectangle(indentation, composite.Height / 2 - GLYPH_SIZE / 2, GLYPH_SIZE, GLYPH_SIZE);
                VisualStyleElement elem        = bitmapInfo.NodeExpanded ? VisualStyleElement.TreeView.Glyph.Opened : VisualStyleElement.TreeView.Glyph.Closed;

                if (_sourceControl.DrawWithVisualStyles && VisualStyleRenderer.IsSupported && VisualStyleRenderer.IsElementDefined(elem))
                {
                    // visual style support, render using visual styles
                    VisualStyleRenderer r = new VisualStyleRenderer(elem);
                    r.DrawBackground(g, glyphBounds);
                }
                else
                {
                    // no visual style support, render using bitmap
                    Image glyph = bitmapInfo.NodeExpanded ? Expanded : Collapsed;
                    g.DrawImage(glyph, glyphBounds);
                }
            }
        }

        return(composite);
    }
Example #19
0
        public void VisualStyleRenderer_IsElementDefined_NullElementClassName_ThrowsArgumentNullException()
        {
            VisualStyleElement element = VisualStyleElement.CreateElement(null, 0, 0);

            Assert.Throws <ArgumentNullException>("className", () => VisualStyleRenderer.IsElementDefined(element));
        }
Example #20
0
 public static bool IsElementDefined(VisualStyleElement element)
 {
     return(VisualStyleRenderer.IsElementDefined(element));
 }
Example #21
0
 public void VisualStyleRenderer_Ctor_InvalidClassNamePartOrState_ThrowsArgumentException(VisualStyleElement element)
 {
     Assert.Throws <ArgumentException>(null, () => new VisualStyleRenderer(element.ClassName, element.Part, element.State));
 }
Example #22
0
        protected override void OnRenderSplitButtonBackground(ToolStripItemRenderEventArgs e)
        {
            ToolStripSplitButton splitButton = e.Item as ToolStripSplitButton;
            Graphics             g           = e.Graphics;

            bool  rightToLeft = (splitButton.RightToLeft == RightToLeft.Yes);
            Color arrowColor  = splitButton.Enabled ? SystemColors.ControlText : SystemColors.ControlDark;

            // in right to left - we need to swap the parts so we dont draw  v][ toolStripSplitButton
            VisualStyleElement splitButtonDropDownPart = (rightToLeft) ? VisualStyleElement.ToolBar.SplitButton.Normal : VisualStyleElement.ToolBar.SplitButtonDropDown.Normal;
            VisualStyleElement splitButtonPart         = (rightToLeft) ? VisualStyleElement.ToolBar.DropDownButton.Normal : VisualStyleElement.ToolBar.SplitButton.Normal;

            Rectangle bounds = new Rectangle(Point.Empty, splitButton.Size);

            if (ToolStripManager.VisualStylesEnabled &&
                VisualStyleRenderer.IsElementDefined(splitButtonDropDownPart) &&
                VisualStyleRenderer.IsElementDefined(splitButtonPart))
            {
                VisualStyleRenderer vsRenderer = VisualStyleRenderer;

                // Draw the SplitButton Button portion of it.
                vsRenderer.SetParameters(splitButtonPart.ClassName, splitButtonPart.Part, GetSplitButtonItemState(splitButton));

                // the lovely Windows theming for split button comes in three pieces:
                //  SplitButtonDropDown: [ v |
                //  Separator:                |
                //  SplitButton:               |  ]
                // this is great except if you want to swap the button in RTL.  In this case we need
                // to use the DropDownButton instead of the SplitButtonDropDown and paint the arrow ourselves.
                Rectangle splitButtonBounds = splitButton.ButtonBounds;
                if (rightToLeft)
                {
                    // scoot to the left so we dont draw double shadow like so: ][
                    splitButtonBounds.Inflate(2, 0);
                }
                // Draw the button portion of it.
                vsRenderer.DrawBackground(g, splitButtonBounds);

                // Draw the SplitButton DropDownButton portion of it.
                vsRenderer.SetParameters(splitButtonDropDownPart.ClassName, splitButtonDropDownPart.Part, GetSplitButtonDropDownItemState(splitButton));

                // Draw the drop down button portion
                vsRenderer.DrawBackground(g, splitButton.DropDownButtonBounds);

                // fill in the background image
                Rectangle fillRect = splitButton.ContentRectangle;
                if (splitButton.BackgroundImage != null)
                {
                    ControlPaint.DrawBackgroundImage(g, splitButton.BackgroundImage, splitButton.BackColor, splitButton.BackgroundImageLayout, fillRect, fillRect);
                }

                // draw the separator over it.
                RenderSeparatorInternal(g, splitButton, splitButton.SplitterBounds, true);

                // and of course, now if we're in RTL we now need to paint the arrow
                // because we're no longer using a part that has it built in.
                if (rightToLeft || splitButton.BackgroundImage != null)
                {
                    DrawArrow(new ToolStripArrowRenderEventArgs(g, splitButton, splitButton.DropDownButtonBounds, arrowColor, ArrowDirection.Down));
                }
            }
            else
            {
                // Draw the split button button
                Rectangle splitButtonButtonRect = splitButton.ButtonBounds;

                if (splitButton.BackgroundImage != null)
                {
                    // fill in the background image
                    Rectangle fillRect = (splitButton.Selected) ? splitButton.ContentRectangle : bounds;
                    if (splitButton.BackgroundImage != null)
                    {
                        ControlPaint.DrawBackgroundImage(g, splitButton.BackgroundImage, splitButton.BackColor, splitButton.BackgroundImageLayout, bounds, fillRect);
                    }
                }
                else
                {
                    FillBackground(g, splitButtonButtonRect, splitButton.BackColor);
                }

                ToolBarState state = GetSplitButtonToolBarState(splitButton, false);

                RenderSmall3DBorderInternal(g, splitButtonButtonRect, state, rightToLeft);

                // draw the split button drop down
                Rectangle dropDownRect = splitButton.DropDownButtonBounds;

                // fill the color in the dropdown button
                if (splitButton.BackgroundImage == null)
                {
                    FillBackground(g, dropDownRect, splitButton.BackColor);
                }

                state = GetSplitButtonToolBarState(splitButton, true);

                if ((state == ToolBarState.Pressed) || (state == ToolBarState.Hot))
                {
                    RenderSmall3DBorderInternal(g, dropDownRect, state, rightToLeft);
                }

                DrawArrow(new ToolStripArrowRenderEventArgs(g, splitButton, dropDownRect, arrowColor, ArrowDirection.Down));
            }
        }
Example #23
0
        public void VisualStyleRenderer_SetParameters_InvokeVisualStyleElement_Success(VisualStyleElement element)
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);

            renderer.SetParameters(element);
            Assert.Equal(element.ClassName, renderer.Class);
            Assert.Equal(element.Part, renderer.Part);
            Assert.Equal(element.State, renderer.State);
            Assert.Equal(0, renderer.LastHResult);
            Assert.NotEqual(IntPtr.Zero, renderer.Handle);
        }
Example #24
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Returns a value indicating whether or not visual style rendering is supported
 /// in the application and if the specified element can be rendered.
 /// </summary>
 /// ------------------------------------------------------------------------------------
 public static bool CanPaintVisualStyle(VisualStyleElement element)
 {
     return(Application.RenderWithVisualStyles && VisualStyleRenderer.IsElementDefined(element));
 }
Example #25
0
        public void VisualStyleRenderer_SetParameters_InvalidElement_ThrowsArgumentException(VisualStyleElement element)
        {
            var renderer = new VisualStyleRenderer(VisualStyleElement.Button.PushButton.Hot);

            Assert.Throws <ArgumentException>(null, () => renderer.SetParameters(element));
        }
 /// <devdoc>
 ///    <para>
 ///       Constructor takes a VisualStyleElement.
 ///    </para>
 /// </devdoc>
 public VisualStyleRenderer(VisualStyleElement element) : this(element.ClassName, element.Part, element.State)
 {
 }
Example #27
0
 public void VisualStyleRenderer_Ctor_InvalidElement_ThrowsArgumentException(VisualStyleElement element)
 {
     Assert.Throws <ArgumentException>(null, () => new VisualStyleRenderer(element));
 }
Example #28
0
        public virtual void PaintCellPlusMinus(Graphics dc, Rectangle glyphRect, Node node, TreeListColumn column, TreeList.TextFormatting format)
        {
            if (!Application.RenderWithVisualStyles)
            {
                // find square rect first
                int diff = glyphRect.Height - glyphRect.Width;
                glyphRect.Y      += diff / 2;
                glyphRect.Height -= diff;

                // draw 8x8 box centred
                while (glyphRect.Height > 8)
                {
                    glyphRect.Height -= 2;
                    glyphRect.Y      += 1;
                    glyphRect.X      += 1;
                }

                // make a box
                glyphRect.Width = glyphRect.Height;

                // clear first
                SolidBrush brush = new SolidBrush(format.BackColor);
                if (format.BackColor == Color.Transparent)
                {
                    brush = new SolidBrush(m_owner.BackColor);
                }
                dc.FillRectangle(brush, glyphRect);
                brush.Dispose();

                // draw outline
                Pen p = new Pen(SystemColors.ControlDark);
                dc.DrawRectangle(p, glyphRect);
                p.Dispose();

                p = new Pen(SystemColors.ControlText);

                // reduce box for internal lines
                glyphRect.X     += 2; glyphRect.Y += 2;
                glyphRect.Width -= 4; glyphRect.Height -= 4;

                // draw horizontal line always
                dc.DrawLine(p, glyphRect.X, glyphRect.Y + glyphRect.Height / 2, glyphRect.X + glyphRect.Width, glyphRect.Y + glyphRect.Height / 2);

                // draw vertical line if this should be a +
                if (!node.Expanded)
                {
                    dc.DrawLine(p, glyphRect.X + glyphRect.Width / 2, glyphRect.Y, glyphRect.X + glyphRect.Width / 2, glyphRect.Y + glyphRect.Height);
                }

                p.Dispose();
                return;
            }

            VisualStyleElement element = VisualStyleElement.TreeView.Glyph.Closed;

            if (node.Expanded)
            {
                element = VisualStyleElement.TreeView.Glyph.Opened;
            }

            if (VisualStyleRenderer.IsElementDefined(element))
            {
                VisualStyleRenderer renderer = new VisualStyleRenderer(element);
                renderer.DrawBackground(dc, glyphRect);
            }
        }
Example #29
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Draws the button in the cell.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void DrawButton(Graphics g, Rectangle rcbtn, int rowIndex)
        {
            if (!InternalShowButton(rowIndex))
            {
                return;
            }

            bool paintComboButton = (OwningButtonColumn != null && OwningButtonColumn.UseComboButtonStyle);

            VisualStyleElement element = (paintComboButton ?
                                          GetVisualStyleComboButton() : GetVisualStylePushButton());

            if (PaintingHelper.CanPaintVisualStyle(element))
            {
                VisualStyleRenderer renderer = new VisualStyleRenderer(element);

                if (!OwningButtonColumn.DrawDefaultComboButtonWidth)
                {
                    renderer.DrawBackground(g, rcbtn);
                }
                else
                {
                    Rectangle rc = rcbtn;
                    Size      sz = renderer.GetPartSize(g, rc, ThemeSizeType.True);
                    rc.Width = sz.Width + 2;
                    rc.X     = (rcbtn.Right - rc.Width);
                    renderer.DrawBackground(g, rc);
                }
            }
            else
            {
                ButtonState state = (m_mouseDownOnButton && m_mouseOverButton && m_enabled ?
                                     ButtonState.Pushed : ButtonState.Normal);

                if (!m_enabled)
                {
                    state |= ButtonState.Inactive;
                }

                if (paintComboButton)
                {
                    ControlPaint.DrawComboButton(g, rcbtn, state);
                }
                else
                {
                    ControlPaint.DrawButton(g, rcbtn, state);
                }
            }

            string buttonText = (OwningButtonColumn == null ? null : OwningButtonColumn.ButtonText);

            if (string.IsNullOrEmpty(buttonText))
            {
                return;
            }

            Font buttonFont = (OwningButtonColumn == null ?
                               SystemInformation.MenuFont : OwningButtonColumn.ButtonFont);

            // Draw text
            TextFormatFlags flags = TextFormatFlags.HorizontalCenter |
                                    TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine |
                                    TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis |
                                    TextFormatFlags.NoPadding | TextFormatFlags.PreserveGraphicsClipping;

            Color clrText = (m_enabled ? SystemColors.ControlText : SystemColors.GrayText);

            TextRenderer.DrawText(g, buttonText, buttonFont, rcbtn, clrText, flags);
        }
        private static bool IsElementDefined(VSEInternal e)
        {
            var el = VisualStyleElement.CreateElement(e.cls, e.part, e.state);

            return(VisualStyleRenderer.IsElementDefined(el));
        }
Example #31
0
/// ------------------------------------------------------------------------------------
/// <summary>
/// Returns a value indicating whether or not visual style rendering is supported
/// in the application and if the specified element can be rendered.
/// </summary>
/// ------------------------------------------------------------------------------------
        public static bool CanPaintVisualStyle(VisualStyleElement element)
        {
            return(CanPaintVisualStyle() && VisualStyleRenderer.IsElementDefined(element));
        }
Example #32
0
 /// <summary>
 /// Notifies the DragDropHelper that the specified Window received
 /// a DragEnter event.
 /// </summary>
 /// <param name="window">The Window the received the DragEnter event.</param>
 /// <param name="data">The DataObject containing a drag image.</param>
 /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
 /// <param name="effect">The accepted drag drop effect.</param>
 /// <param name="descriptionMessage">The drop description message.</param>
 /// <param name="descriptionInsert">The drop description insert.</param>
 /// <remarks>Callers of this DragEnter override should make sure to call
 /// the DragLeave override taking an IDataObject parameter in order to clear
 /// the drop description.</remarks>
 public static void DragEnter(VisualStyleElement.Window window, IDataObject data, Point cursorOffset, DragDropEffects effect, string descriptionMessage, string descriptionInsert)
 {
     data.SetDropDescription((DropImageType)effect, descriptionMessage, descriptionInsert);
     DragEnter(window, data, cursorOffset, effect);
 }
Example #33
0
 public void SetParameters(VisualStyleElement element)
 {
     this.SetParameters(element.ClassName, element.Part, element.State);
 }
 public void SetParameters(VisualStyleElement element)
 {
 }
 /// <summary>
 /// Gets the System.Windows.Forms.VisualStyles.VisualStyleRenderer to draw the specified element.
 /// </summary>
 /// <param name="element"></param>
 /// <returns></returns>
 protected System.Windows.Forms.VisualStyles.VisualStyleRenderer GetRenderer(VisualStyleElement element)
 {
     return(new System.Windows.Forms.VisualStyles.VisualStyleRenderer(element));
 }
 // Methods
 public static bool IsElementDefined(VisualStyleElement element)
 {
 }
Example #37
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
        {
            e.DrawDefault = false;
            Rectangle rect = e.Bounds;

            if (rect.Height == 0)
            {
                ///在展开节点的时候会出现根节点绘制错误的问题
                return;
            }
            if ((e.State & TreeNodeStates.Selected) != 0)
            {
                e.Graphics.FillRectangle(
                    (e.State & TreeNodeStates.Focused) != 0 ? SystemBrushes.Highlight : SystemBrushes.Control, rect);
            }
            else
            {
                e.Graphics.FillRectangle(Brushes.White, rect);
            }
            int IndentWidth = DatatreeView.Indent * e.Node.Level + 25;

            e.Graphics.DrawRectangle(SystemPens.Control, rect);
            var StringRect = new Rectangle(e.Bounds.X + IndentWidth, e.Bounds.Y, colName.Width - IndentWidth,
                                           e.Bounds.Height);

            String TreeNameString = e.Node.Text;

            if (TreeNameString.EndsWith(MongoDbHelper.Array_Mark))
            {
                //Array_Mark 在计算路径的时候使用,不过,在表示的时候,则不能表示
                TreeNameString = TreeNameString.Substring(0, TreeNameString.Length - MongoDbHelper.Array_Mark.Length);
            }
            if (TreeNameString.EndsWith(MongoDbHelper.Document_Mark))
            {
                //Document_Mark 在计算路径的时候使用,不过,在表示的时候,则不能表示
                TreeNameString = TreeNameString.Substring(0, TreeNameString.Length - MongoDbHelper.Document_Mark.Length);
            }
            //感谢cyrus的建议,选中节点的文字表示,底色变更
            if ((e.State & TreeNodeStates.Selected) != 0 && (e.State & TreeNodeStates.Focused) != 0)
            {
                e.Graphics.DrawString(TreeNameString, Font, new SolidBrush(SystemColors.HighlightText), StringRect);
            }
            else
            {
                e.Graphics.DrawString(TreeNameString, Font, new SolidBrush(Color.Black), StringRect);
            }

            var mElement = e.Node.Tag as BsonElement;
            var mValue   = e.Node.Tag as BsonValue;

            //画框
            if (e.Node.GetNodeCount(true) > 0 ||
                (mElement != null && (mElement.Value.IsBsonDocument || mElement.Value.IsBsonArray)))
            {
                //感谢Cyrus测试出来的问题:RenderWithVisualStyles应该加上去的。
                if (VisualStyleRenderer.IsSupported && Application.RenderWithVisualStyles)
                {
                    int LeftPoint = e.Bounds.X + IndentWidth - 20;
                    //感谢 Shadower http://home.cnblogs.com/u/14697/ 贡献的代码
                    TreeNode           thisNode = e.Node;
                    VisualStyleElement glyph    = thisNode.IsExpanded
                        ? VisualStyleElement.TreeView.Glyph.Opened
                        : VisualStyleElement.TreeView.Glyph.Closed;
                    var vsr = new VisualStyleRenderer(glyph);
                    vsr.DrawBackground(e.Graphics, new Rectangle(LeftPoint, e.Bounds.Y + 4, 16, 16));
                }
                else
                {
                    int LeftPoint = e.Bounds.X + IndentWidth - 20;
                    e.Graphics.DrawRectangle(new Pen(Color.Black), new Rectangle(LeftPoint, e.Bounds.Y + 4, 12, 12));
                    var LeftMid   = new Point(LeftPoint + 2, e.Bounds.Y + 10);
                    var RightMid  = new Point(LeftPoint + 10, e.Bounds.Y + 10);
                    var TopMid    = new Point(LeftPoint + 6, e.Bounds.Y + 6);
                    var BottomMid = new Point(LeftPoint + 6, e.Bounds.Y + 14);
                    e.Graphics.DrawLine(new Pen(Color.Black), LeftMid, RightMid);
                    if (!e.Node.IsExpanded)
                    {
                        e.Graphics.DrawLine(new Pen(Color.Black), TopMid, BottomMid);
                    }
                }
            }

            for (int intColumn = 1; intColumn < 3; intColumn++)
            {
                rect.Offset(listView.Columns[intColumn - 1].Width, 0);
                rect.Width = listView.Columns[intColumn].Width;
                e.Graphics.DrawRectangle(SystemPens.Control, rect);
                if (mElement != null || mValue != null)
                {
                    string strColumnText = String.Empty;
                    if (intColumn == 1)
                    {
                        if (mElement != null)
                        {
                            if (!mElement.Value.IsBsonDocument && !mElement.Value.IsBsonArray)
                            {
                                strColumnText = mElement.Value.ToString();
                            }
                        }
                        else
                        {
                            if (mValue != null)
                            {
                                //Type这里已经有表示Type的标识了,这里就不重复显示了。
                                if (!mValue.IsBsonDocument && !mValue.IsBsonArray)
                                {
                                    if (e.Node.Level > 0)
                                    {
                                        //根节点有Value,可能是ID,用来取得选中节点的信息
                                        strColumnText = mValue.ToString();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        strColumnText = mElement != null
                            ? mElement.Value.GetType().Name.Substring(4)
                            : mValue.GetType().Name.Substring(4);
                    }

                    var flags = TextFormatFlags.EndEllipsis;
                    switch (listView.Columns[intColumn].TextAlign)
                    {
                    case HorizontalAlignment.Center:
                        flags |= TextFormatFlags.HorizontalCenter;
                        break;

                    case HorizontalAlignment.Left:
                        flags |= TextFormatFlags.Left;
                        break;

                    case HorizontalAlignment.Right:
                        flags |= TextFormatFlags.Right;
                        break;

                    default:
                        break;
                    }

                    rect.Y++;
                    if ((e.State & TreeNodeStates.Selected) != 0 &&
                        (e.State & TreeNodeStates.Focused) != 0)
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect,
                                              SystemColors.HighlightText, flags);
                    }
                    else
                    {
                        TextRenderer.DrawText(e.Graphics, strColumnText, e.Node.NodeFont, rect, e.Node.ForeColor,
                                              e.Node.BackColor, flags);
                    }
                    rect.Y--;
                }
            }
        }