Esempio n. 1
0
        private void DrawTabs(Graphics g)
        {
            var borderPen        = new Pen(BorderColor);
            var activeTabBrush   = new SolidBrush(ActiveTabColor);
            var inactiveTabBrush = new LinearGradientBrush(
                new Rectangle(0, 5, Width, Height - 1), ActiveTabColor,
                SystemColors.ControlLight, LinearGradientMode.Vertical);
            var left = LeftMargin;

            var textBrush = ForeColor.IsKnownColor ? SystemBrushes.FromSystemColor(ForeColor) : new SolidBrush(ForeColor);

            g.DrawLine(borderPen, 0, Height - 1, left, Height - 1);
            foreach (Tab tab in tabs)
            {
                var top          = (tab.IsActive ? TopMargin : TopMargin + 2);
                var tabRectangle = new Rectangle(left, top, tab.Width, Height - top);
                tab.Draw(g, tabRectangle, activeTabBrush, inactiveTabBrush, borderPen, textBrush, stringFormat, activeTabFont, Font);
                left += tab.Width;
            }
            g.DrawLine(borderPen, left, Height - 1, Width - 1, Height - 1);

            borderPen.Dispose();
            if (!ForeColor.IsKnownColor)
            {
                textBrush.Dispose();
            }
            activeTabBrush.Dispose();
            inactiveTabBrush.Dispose();
        }
 public virtual void DrawSelectionBackground(Graphics dc, Rectangle nodeRect, Node node)
 {
     if (m_owner.NodesSelection.Contains(node) || m_owner.FocusedNode == node)
     {
         if (!Application.RenderWithVisualStyles)
         {
             // have to fill the solid background only before the node is painted
             dc.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.Highlight), nodeRect);
         }
         else
         {
             // have to draw the transparent background after the node is painted
             VisualStyleItemBackground.Style style = VisualStyleItemBackground.Style.Normal;
             if (m_owner.Focused == false)
             {
                 style = VisualStyleItemBackground.Style.Inactive;
             }
             VisualStyleItemBackground rendere = new VisualStyleItemBackground(style);
             rendere.DrawBackground(m_owner, dc, nodeRect);
         }
     }
     if (m_owner.Focused && (m_owner.FocusedNode == node))
     {
         nodeRect.Height += 1;
         nodeRect.Inflate(-1, -1);
         ControlPaint.DrawFocusRectangle(dc, nodeRect);
     }
 }
Esempio n. 3
0
        protected override void OnPaintBackground(PaintEventArgs pe)
        {
            base.OnPaintBackground(pe);

            StringFormat sf  = new StringFormat(StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap);
            Graphics     g   = pe.Graphics;
            SizeF        lt  = g.MeasureString(this.Text + " ", this.Font, this.Width, sf);
            float        lth = lt.Height / 2;

            Brush h  = new SolidBrush(_highlight);
            Pen   ph = new Pen(h, 1.0f);
            Brush s  = new SolidBrush(_shadow);
            Pen   ps = new Pen(s, 1.0f);

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SystemDefault;
            g.DrawString(this.Text, this.Font, SystemBrushes.FromSystemColor(this.ForeColor), new PointF(0, 0), sf);
            g.DrawLine(ps, lt.Width, lth, Width, lth);
            g.DrawLine(ph, lt.Width, lth + 1.0f, Width, lth + 1.0f);

            if (this._image != null)
            {
                g.DrawImage(this._image, _imageLocation.X, _imageLocation.Y, this._image.Width, this._image.Height);
            }

            sf.Dispose();
            ph.Dispose();
            ps.Dispose();
            h.Dispose();
            s.Dispose();
        }
Esempio n. 4
0
 protected virtual void OnDrawMenuItem(EZSDrawItemEventArgs e)
 {
     e.DrawBackground();
     using (var brush = (e.ForeColor.IsSystemColor) ? SystemBrushes.FromSystemColor(e.ForeColor) : new SolidBrush(e.ForeColor))
     {
         e.Graphics.DrawString(e.MenuItem.Caption, e.Font, brush, new PointF((float)e.Bounds.Left, (float)e.Bounds.Top));
     }
 }
Esempio n. 5
0
        // Main paiting method
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            var maxItem = Items.Count - 1;

            if (e.Index < 0 || e.Index > maxItem)
            {
                // Erase all background if control has no items
                e.Graphics.FillRectangle(_backBrush, ClientRectangle);
                return;
            }

            // Calculate bounds for background, if last item paint up to bottom of control
            var backRect = e.Bounds;

            if (e.Index == maxItem)
            {
                backRect.Height = ClientRectangle.Top + ClientRectangle.Height - e.Bounds.Top;
            }
            e.Graphics.FillRectangle(_backBrush, backRect);

            // Determines text color/brush
            Brush textBrush;
            var   isChecked = (e.State & DrawItemState.Selected) == DrawItemState.Selected;

            var state = isChecked ? RadioButtonState.CheckedNormal : RadioButtonState.UncheckedNormal;

            if ((e.State & DrawItemState.Disabled) == DrawItemState.Disabled)
            {
                textBrush = SystemBrushes.GrayText;
                state     = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled;
            }
            else if ((e.State & DrawItemState.Grayed) == DrawItemState.Grayed)
            {
                textBrush = SystemBrushes.GrayText;
                state     = isChecked ? RadioButtonState.CheckedDisabled : RadioButtonState.UncheckedDisabled;
            }
            else
            {
                textBrush = SystemBrushes.FromSystemColor(ForeColor);
            }

            // Determines bounds for text and radio button
            var glyphSize     = RadioButtonRenderer.GetGlyphSize(e.Graphics, state);
            var glyphLocation = e.Bounds.Location;

            glyphLocation.Y += (e.Bounds.Height - glyphSize.Height) / 2;

            var bounds = new Rectangle(e.Bounds.X + glyphSize.Width, e.Bounds.Y, e.Bounds.Width - glyphSize.Width, e.Bounds.Height);

            // Draws the radio button
            RadioButtonRenderer.DrawRadioButton(e.Graphics, glyphLocation, state);

            // Draws the text
            e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, textBrush, bounds, _align);

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }
Esempio n. 6
0
        public virtual void DrawSelectionBackground(Graphics dc, Rectangle nodeRect, Node node)
        {
            Point mousePoint = m_owner.PointToClient(Cursor.Position);
            Node  hoverNode  = m_owner.CalcHitNode(mousePoint);

            if (m_owner.NodesSelection.Contains(node) || m_owner.FocusedNode == node)
            {
                Color col = m_owner.Focused ? SystemColors.Highlight : SystemColors.ControlLight;

                if (!Application.RenderWithVisualStyles)
                {
                    // have to fill the solid background only before the node is painted
                    dc.FillRectangle(SystemBrushes.FromSystemColor(col), nodeRect);
                }
                else
                {
                    col = m_owner.Focused ? SystemColors.Highlight : Color.FromArgb(180, SystemColors.ControlDark);

                    // have to draw the transparent background after the node is painted
                    VisualStyleItemBackground.Style style = VisualStyleItemBackground.Style.Normal;
                    if (m_owner.Focused == false)
                    {
                        style = VisualStyleItemBackground.Style.Inactive;
                    }
                    VisualStyleItemBackground rendere = new VisualStyleItemBackground(style);
                    rendere.DrawBackground(m_owner, dc, nodeRect, col);
                }
            }
            else if (hoverNode == node && m_owner.RowOptions.HoverHighlight)
            {
                Color col = SystemColors.ControlLight;

                if (!Application.RenderWithVisualStyles)
                {
                    // have to fill the solid background only before the node is painted
                    dc.FillRectangle(SystemBrushes.FromSystemColor(col), nodeRect);
                }
                else
                {
                    // have to draw the transparent background after the node is painted
                    VisualStyleItemBackground.Style style = VisualStyleItemBackground.Style.Normal;
                    if (m_owner.Focused == false)
                    {
                        style = VisualStyleItemBackground.Style.Inactive;
                    }
                    VisualStyleItemBackground rendere = new VisualStyleItemBackground(style);
                    rendere.DrawBackground(m_owner, dc, nodeRect, col);
                }
            }

            if (m_owner.Focused && (m_owner.FocusedNode == node))
            {
                nodeRect.Height += 1;
                nodeRect.Inflate(-1, -1);
                ControlPaint.DrawFocusRectangle(dc, nodeRect);
            }
        }
Esempio n. 7
0
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            if (e.Index > this.Items.Count - 1)
            {
                return;
            }

            int size = e.Font.Height; // button size depends on font height, not on item height

            if (IsTransparent && e.State != DrawItemState.Selected)
            {
                e.Graphics.FillRectangle(TransparentBrush, e.Bounds);
            }
            else
            {
                e.DrawBackground();
            }

            Brush       textBrush;
            ButtonState state = ButtonState.Normal;

            if ((e.State & DrawItemState.Disabled) > 0 || (e.State & DrawItemState.Grayed) > 0)
            {
                textBrush = SystemBrushes.GrayText;
                state     = ButtonState.Inactive;
            }
            else if ((e.State & DrawItemState.Selected) > 0 && !Transparent)
            {
                textBrush = SystemBrushes.HighlightText;
            }
            else
            {
                textBrush = SystemBrushes.FromSystemColor(this.ForeColor);
            }
            if ((e.State & DrawItemState.Selected) > 0)
            {
                state |= ButtonState.Checked;
            }

            // Draw radio button
            Rectangle bounds = e.Bounds;

            bounds.Width = size;
            ControlPaint.DrawRadioButton(e.Graphics, bounds, state);

            // Draw text
            bounds = new Rectangle(e.Bounds.X + size + 2, e.Bounds.Y, e.Bounds.Width - size - 2, e.Bounds.Height);
            e.Graphics.DrawString(this.Items[e.Index].ToString(), e.Font, textBrush, bounds, this.Align);

            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
        }
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            //OnDrawItem perfoms the task of actually drawing the item after measurement is complete
            base.OnDrawItem(e);

            Brush br = SystemBrushes.Control;

            //Let the Icon area have the same background as the rest of the menu entry...
            Rectangle rectCheck = e.Bounds;
            Rectangle rectText  = e.Bounds;

            rectCheck.Width = rectCheck.Height;
            //Draw the main rectangle
            e.Graphics.FillRectangle(br, rectText);

            //Draw a background to the menu item with a linear gradient. This will use system defaults unless colors and have been
            //passed on menu item instantiation
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                br = new System.Drawing.Drawing2D.LinearGradientBrush(rectText, mGradientColor1, mGradientColor2, System.Drawing.Drawing2D.LinearGradientMode.Horizontal);
            }

            //Adjust rectangle for icon/CheckMark area and fill...
            float adjust = Convert.ToSingle(Microsoft.VisualBasic.Interaction.IIf(base.Parent is MainMenu, 0, rectCheck.Width));

            rectText.X += Convert.ToInt32(adjust);
            e.Graphics.FillRectangle(br, rectText);

            //Now that the menuItem background has been filled, draw any Icon we may need...
            if ((mIcon != null))
            {
                e.Graphics.DrawIcon(mIcon, e.Bounds.Left + 2, e.Bounds.Top + 2);
            }

            //Leave room for accelerator key
            StringFormat sf = new StringFormat();

            sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

            //Draw the actual menu text (adjusting for icon-space for all but top-level menuItems)...
            br = new SolidBrush(e.ForeColor);
            if (!base.Enabled)
            {
                br = SystemBrushes.FromSystemColor(SystemColors.GrayText);
            }
            e.Graphics.DrawString(Text, mFont, br, e.Bounds.Left + 2 + adjust, e.Bounds.Top + 2, sf);
            //Debug.WriteLine(String.Format("OnDrawItem(e): e.Graphics.DrawString(""{0}"", {{{1}}}:={2}, {{{3}}}, e.Bounds.Left + 2 + adjust ({4} + 2 + {5} = {6}), e.Bounds.Top + 2  ({7} + 2 = {8}), {{{9}}})", New Object() {Text, mFont.GetType.Name, mFont.Name, br.GetType.Name, e.Bounds.Left, adjust, e.Bounds.Left + 2 + adjust, e.Bounds.Top, e.Bounds.Top + 2, sf.GetType.Name}))
            string ShortcutText = GetShortcutText();

            if (!string.IsNullOrEmpty(ShortcutText))
            {
                float ShortCutWidth = e.Graphics.MeasureString(ShortcutText, mFont, maxWidth, sf).Width;
                e.Graphics.DrawString(ShortcutText, mFont, br, e.Bounds.Right - ShortCutWidth - 10, e.Bounds.Top + 2, sf);
                //Debug.WriteLine(String.Format("OnDrawItem(e): e.Graphics.DrawString(""{0}"", {{{1}}}:={2}, {{{3}}}, e.Bounds.Right - ShortCutWidth - 10 ({4} - {5} - 10 = {6}), e.Bounds.Top + 2  ({7} + 2 = {8}), {{{9}}})", New Object() {ShortcutText, mFont.GetType.Name, mFont.Name, br.GetType.Name, e.Bounds.Right, ShortCutWidth, e.Bounds.Right - ShortCutWidth - 10, e.Bounds.Top, e.Bounds.Top + 2, sf.GetType.Name}))
            }
        }
Esempio n. 9
0
        private void draw_link(Labyrinth.Plot.Link l, Graphics g, Rectangle rect)
        {
            Node node1 = this.find_node(l.LHS);
            Node node2 = this.find_node(l.RHS);

            if (node1 == null || node2 == null)
            {
                return;
            }
            int    num1     = (int)((double)node1.Position.X * (double)rect.Width) + rect.Left;
            PointF position = node1.Position;
            int    num2     = (int)((double)position.Y * (double)rect.Height) + rect.Top;
            PointF pointF1  = new PointF((float)num1, (float)num2);

            position = node2.Position;
            int num3 = (int)((double)position.X * (double)rect.Width) + rect.Left;

            position = node2.Position;
            int    num4    = (int)((double)position.Y * (double)rect.Height) + rect.Top;
            PointF pointF2 = new PointF((float)num3, (float)num4);

            g.DrawLine(SystemPens.ControlText, pointF1, pointF2);
            if (this.fShowText)
            {
                PointF pointF3 = this.get_intersection(pointF2, pointF1, this.rect_for_node(node1, rect));
                PointF pointF4 = this.get_intersection(pointF1, pointF2, this.rect_for_node(node2, rect));
                if (this.fShowArrows)
                {
                    if (l.Direction == LinkDirection.Single || l.Direction == LinkDirection.Double)
                    {
                        pointF4 = this.find_arrow_point(pointF3, pointF4);
                    }
                    if (l.Direction == LinkDirection.Double)
                    {
                        pointF3 = this.find_arrow_point(pointF4, pointF3);
                    }
                }
                SizeF      textSize   = this.get_text_size(l.Description, this.fSmallFont);
                RectangleF rectangleF = new RectangleF(new PointF((float)(((double)pointF3.X + (double)pointF4.X) / 2.0 - (double)textSize.Width / 2.0), (float)(((double)pointF3.Y + (double)pointF4.Y) / 2.0 - (double)textSize.Height / 2.0)), textSize);
                g.FillRectangle(SystemBrushes.FromSystemColor(this.BackColor), rectangleF);
                g.DrawString(l.Description, this.fSmallFont, SystemBrushes.WindowText, rectangleF, this.fStringFormat);
            }
            if (!this.fShowArrows)
            {
                return;
            }
            if (l.Direction == LinkDirection.Single || l.Direction == LinkDirection.Double)
            {
                this.draw_arrow(node1, node2, g, rect);
            }
            if (l.Direction != LinkDirection.Double)
            {
                return;
            }
            this.draw_arrow(node2, node1, g, rect);
        }
Esempio n. 10
0
        private void DrawTabs(Graphics g)
        {
            var   borderPen        = new Pen(BorderColor);
            Brush activeTabBrush   = new SolidBrush(ActiveTabColor);
            Brush inactiveTabBrush = new LinearGradientBrush(
                new Rectangle(0, 5, Width, Height - 1),
                ActiveTabColor,
                SystemColors.ControlLight,
                LinearGradientMode.Vertical);
            Brush textBrush;
            var   left = LeftMargin;

            if (ForeColor.IsKnownColor)
            {
                textBrush = SystemBrushes.FromSystemColor(ForeColor);
            }
            else
            {
                textBrush = new SolidBrush(ForeColor);
            }

            g.DrawLine(borderPen, 0, Height - 1, left, Height - 1);
            foreach (var tab in tabs)
            {
                //TODO: szépíteni
                var isActiveTab  = tab == activeTab;
                var top          = isActiveTab ? TopMargin : TopMargin + 2;
                var tabBrush     = isActiveTab ? activeTabBrush : inactiveTabBrush;
                var tabRectangle = new Rectangle(left, top, tab.Width, Height - top);

                // To display bottom line for inactive tabs
                if (!isActiveTab)
                {
                    tabRectangle.Height--;
                }

                g.FillRectangle(tabBrush, tabRectangle);  // Draw background
                g.DrawRectangle(borderPen, tabRectangle); // Draw border
                var font = isActiveTab ? activeTabFont : Font;
                g.DrawString(tab.Text, font, textBrush, tabRectangle, stringFormat);

                left += tab.Width;
            }
            g.DrawLine(borderPen, left, Height - 1, Width - 1, Height - 1);

            borderPen.Dispose();
            if (!ForeColor.IsKnownColor)
            {
                textBrush.Dispose();
            }
            activeTabBrush.Dispose();
            inactiveTabBrush.Dispose();
        }
Esempio n. 11
0
 protected static void FillBackground(Graphics g, Rectangle bounds, Color backColor)
 {
     if (backColor.IsSystemColor)
     {
         g.FillRectangle(SystemBrushes.FromSystemColor(backColor), bounds);
     }
     else
     {
         using (Brush brush = new SolidBrush(backColor)) {
             g.FillRectangle(brush, bounds);
         }
     }
 }
Esempio n. 12
0
        private void RenderRadio(Context ctx, State.Radio stateid, Rectangle prect)
        {
            Brush backBrush;
            Color foreColor;

            switch (stateid)
            {
            case State.Radio.RBS_UNCHECKEDNORMAL:
            case State.Radio.RBS_CHECKEDNORMAL:
                backBrush = SystemBrushes.Window;
                foreColor = SystemColors.WindowText;
                break;

            case State.Radio.RBS_UNCHECKEDHOT:
            case State.Radio.RBS_CHECKEDHOT:
                backBrush = SystemBrushes.Window;
                foreColor = SystemColors.HotTrack;
                break;

            case State.Radio.RBS_UNCHECKEDPRESSED:
            case State.Radio.RBS_CHECKEDPRESSED:
                backBrush = SystemBrushes.ControlLightLight;
                foreColor = SystemColors.HotTrack;
                break;

            // case State.Radio.RBS_UNCHECKEDDISABLED:
            // case State.Radio.RBS_CHECKEDDISABLED:
            default:
                backBrush = SystemBrushes.ControlLight;
                foreColor = SystemColors.ControlDark;
                break;
            }

            using (ctx.HighQuality())
            {
                var rect = prect.Inclusive();
                ctx.Graphics.FillEllipse(backBrush, rect);
                ctx.Graphics.DrawEllipse(SystemPens.FromSystemColor(foreColor), rect);
                var padding = DpiUtil.Scale(new Size(-3, -3));
                switch (stateid)
                {
                case State.Radio.RBS_CHECKEDNORMAL:
                case State.Radio.RBS_CHECKEDHOT:
                case State.Radio.RBS_CHECKEDPRESSED:
                case State.Radio.RBS_CHECKEDDISABLED:
                    rect.Inflate(padding);
                    ctx.Graphics.FillEllipse(SystemBrushes.FromSystemColor(foreColor), rect);
                    break;
                }
            }
        }
Esempio n. 13
0
 /// <devdoc>
 ///     Fill the item's background as bounded by the rectangle
 /// </devdoc>
 private static void FillBackground(Graphics g, Rectangle bounds, Color backColor)
 {
     // Fill the background with the item's back color
     if (backColor.IsSystemColor)
     {
         g.FillRectangle(SystemBrushes.FromSystemColor(backColor), bounds);
     }
     else
     {
         using (Brush backBrush = new SolidBrush(backColor)) {
             g.FillRectangle(backBrush, bounds);
         }
     }
 }
Esempio n. 14
0
        public void TestFromSystemColor()
        {
            SolidBrush brush;

            brush = (SolidBrush)SystemBrushes.FromSystemColor(SystemColors.Menu);
            Assert.AreEqual(SystemColors.Menu, brush.Color, "M1#1");

            try
            {
                brush.Color = Color.Red;
                Assert.Fail("M1#2: must throw ArgumentException");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentException, "M1#2");
            }

            try
            {
                brush.Color = SystemColors.Menu;
                Assert.Fail("M1#3: must throw ArgumentException");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentException, "M1#3");
            }

            try
            {
                brush.Dispose();
                Assert.Fail("M1#4: must throw ArgumentException");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentException, "M1#4");
            }


            try
            {
                brush = (SolidBrush)SystemBrushes.FromSystemColor(Color.Red);
                Assert.Fail("M2#1: must throw ArgumentException");
            }
            catch (Exception e)
            {
                Assert.IsTrue(e is ArgumentException, "M2#1");
            }
        }
Esempio n. 15
0
        private static SolidBrushCache.Scope GetSolidBrushScope(Color color)
        {
            if (color.IsKnownColor)
            {
                SolidBrush?solidBrush = color.IsSystemColor
                    ? (SolidBrush?)SystemBrushes.FromSystemColor(color)
                    : (SolidBrush?)BrushFromKnownColor(color.ToKnownColor());

                if (solidBrush is not null)
                {
                    return(new SolidBrushCache.Scope(solidBrush));
                }
            }

            return(BrushCache.GetEntry(color));
        }
Esempio n. 16
0
        protected override void RenderNodeOutline(Graphics graphics, KTreeNode node, Rectangle rect, KTreeNodeMeasurements.Part?highlight)
        {
            if (highlight != null)
            {
                graphics.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.HotTrack), rect);
            }
            else if (node.IsSelected)
            {
                graphics.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.Highlight), rect);
            }

            if (_tree.ActiveNode == node && !node.IsSelected)
            {
                graphics.DrawRectangle(SystemPens.FromSystemColor(SystemColors.HotTrack), rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
            }
        }
Esempio n. 17
0
 protected override void OnDrawItem(DrawItemEventArgs e)
 {
     if ((e.Index >= 0) && (e.Index <= (base.Items.Count - 1)))
     {
         Brush grayText;
         int   height = e.Font.Height;
         if (this.IsTransparent && (e.State != DrawItemState.Selected))
         {
             e.Graphics.FillRectangle(this.TransparentBrush, e.Bounds);
         }
         else
         {
             e.DrawBackground();
         }
         ButtonState normal = ButtonState.Normal;
         if (((e.State & DrawItemState.Disabled) > DrawItemState.None) || ((e.State & DrawItemState.Grayed) > DrawItemState.None))
         {
             grayText = SystemBrushes.GrayText;
             normal   = ButtonState.Inactive;
         }
         else if (((e.State & DrawItemState.Selected) > DrawItemState.None) && !this.Transparent)
         {
             grayText = SystemBrushes.HighlightText;
         }
         else
         {
             grayText = SystemBrushes.FromSystemColor(this.ForeColor);
         }
         if ((e.State & DrawItemState.Selected) > DrawItemState.None)
         {
             normal |= ButtonState.Checked;
         }
         Rectangle bounds = e.Bounds;
         bounds.Width = height;
         if (!this._isCheckBox)
         {
             ControlPaint.DrawRadioButton(e.Graphics, bounds, normal);
         }
         else
         {
             ControlPaint.DrawCheckBox(e.Graphics, bounds, normal);
         }
         bounds = new Rectangle((e.Bounds.X + height) + 2, e.Bounds.Y, (e.Bounds.Width - height) - 2, e.Bounds.Height);
         e.Graphics.DrawString(base.Items[e.Index].ToString(), e.Font, grayText, bounds, this.Align);
         e.DrawFocusRectangle();
     }
 }
Esempio n. 18
0
        public override void LPaint(LinePaintEvent lpe)
        {
            if (sbuffer == null)
            {
                return;
            }
            if (sbuffer.lindex == null)
            {
                return;
            }
            int virtualoffset = 0, lct = LinesVisible + LineOffset;

            // get the possible strings
            string[] tstr = sbuffer[LineOffset, lct - 1];
            int[]    lin  = sbuffer.Measure(this, tstr);

            Rectangle x_rect;

            for (int i = 0; i < tstr.Length; i++)
            {
                if (LineOffset >= 0)
                {
                    x_rect   = o_rect;
                    x_rect.Y = (virtualoffset * Font.Height);

                    lpe.gfx.DrawString(
                        tstr[i],
                        Font,
                        SystemBrushes.FromSystemColor(ForeColor),
                        x_rect, StrFmt
                        );
                }
                else
                {
                    x_rect   = o_rect;
                    x_rect.Y = (int)Math.Abs((LineOffset)) * Font.Height + (virtualoffset * Font.Height);
                    lpe.gfx.DrawString(
                        tstr[i],
                        Font,
                        SystemBrushes.FromSystemColor(ForeColor),
                        x_rect, StrFmt
                        );
                }
                virtualoffset += lin[i];
            }
        }
Esempio n. 19
0
    //</snippet4>

    // The following code example shows how to set a keyboard shortcut
    // when drawing a string with the Graphics object. It also
    // demonstrates how to use the SystemBrush.FromSystemColor method. To
    // run this example, paste the code into a form, handle the form's
    // Paint event, and call the following method, passing e as
    // PaintEventArgs.
    //<snippet2>
    private void ShowHotKey(PaintEventArgs e)
    {
        // Declare the string with a keyboard shortcut.
        string text = "&Click Here";

        // Declare a new StringFormat.
        StringFormat format = new StringFormat();

        // Set the HotkeyPrefix property.
        format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

        // Draw the string.
        Brush theBrush =
            SystemBrushes.FromSystemColor(SystemColors.Highlight);

        e.Graphics.DrawString(text, this.Font, theBrush, 30, 40, format);
    }
Esempio n. 20
0
    void MenuFacenameOnDrawItem(object obj, DrawItemEventArgs diea)
    {
        MenuItem mi   = (MenuItem)obj;
        Graphics grfx = diea.Graphics;
        Brush    brush;

        // Create the Font and StringFormat.

        Font         font   = new Font(mi.Text.Substring(1), iFontPointSize);
        StringFormat strfmt = new StringFormat();

        strfmt.HotkeyPrefix = HotkeyPrefix.Show;

        // Calculate check mark and text rectangles.

        Rectangle rectCheck = diea.Bounds;

        rectCheck.Width = SystemInformation.MenuCheckSize.Width *
                          rectCheck.Height /
                          SystemInformation.MenuCheckSize.Height;

        Rectangle rectText = diea.Bounds;

        rectText.X += rectCheck.Width;

        // Do all the drawing.

        diea.DrawBackground();

        if ((diea.State & DrawItemState.Checked) != 0)
        {
            ControlPaint.DrawMenuGlyph(grfx, rectCheck, MenuGlyph.Bullet);
        }

        if ((diea.State & DrawItemState.Selected) != 0)
        {
            brush = SystemBrushes.HighlightText;
        }
        else
        {
            brush = SystemBrushes.FromSystemColor(SystemColors.MenuText);
        }

        grfx.DrawString(mi.Text, font, brush, rectText, strfmt);
    }
Esempio n. 21
0
    void MenuFacenameOnDrawItem(object obj, DrawItemEventArgs diea)
    {
        MenuItem mi   = (MenuItem)obj;
        Graphics grfx = diea.Graphics;
        Brush    brush;

        // Создание Font и StringFormat.

        Font         font   = new Font(mi.Text.Substring(1), iFontPointSize);
        StringFormat strfmt = new StringFormat();

        strfmt.HotkeyPrefix = HotkeyPrefix.Show;

        // Вычисление прямоугольников флажка и текста

        Rectangle rectCheck = diea.Bounds;

        rectCheck.Width = SystemInformation.MenuCheckSize.Width *
                          rectCheck.Height /
                          SystemInformation.MenuCheckSize.Height;

        Rectangle rectText = diea.Bounds;

        rectText.X += rectCheck.Width;

        // Выполняем все рисование

        diea.DrawBackground();

        if ((diea.State & DrawItemState.Checked) != 0)
        {
            ControlPaint.DrawMenuGlyph(grfx, rectCheck, MenuGlyph.Bullet);
        }

        if ((diea.State & DrawItemState.Selected) != 0)
        {
            brush = SystemBrushes.HighlightText;
        }
        else
        {
            brush = SystemBrushes.FromSystemColor(SystemColors.MenuText);
        }

        grfx.DrawString(mi.Text, font, brush, rectText, strfmt);
    }
Esempio n. 22
0
    private void MenuFaceNameOnDrawItem(object sender, DrawItemEventArgs diea)
    {
        // After you have established the size of the menu with the OnMeasureItem event you can
        // then go ahead and drawn the item.
        // A graphics object is passed to the OnDrawItem event that you can use to
        // draw the menu item.

        MenuItem mi   = (MenuItem)sender;
        Graphics grfx = diea.Graphics;
        Brush    br;
        Font     f = new Font(mi.Text.Substring(1), pointSize);

        // Shows the accelerator key

        StringFormat strFrmt = new StringFormat();

        strFrmt.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
        Rectangle rectCheck = diea.Bounds;
        Double    d         = SystemInformation.MenuCheckSize.Width * rectCheck.Height / SystemInformation.MenuCheckSize.Width;

        rectCheck.Width = (int)(d);
        Rectangle recText = diea.Bounds;

        // Leave enough room for a checkmark
        recText.X += rectCheck.Width;
        diea.DrawBackground();

        // Highlight the menu item the user moves over it.

        if ((diea.State & DrawItemState.Selected) != 0)
        {
            br = SystemBrushes.HighlightText;
        }
        else
        {
            br = SystemBrushes.FromSystemColor(SystemColors.MenuText);
        }

        // Draws the string leaving room for the accelerator key

        grfx.DrawString(mi.Text, f, br, recText.Left, recText.Top, strFrmt);
    }
Esempio n. 23
0
        void toolTip1_Draw(object sender, DrawToolTipEventArgs e)
        {
            // throw new Exception("The method or operation is not implemented.");
            e.DrawBackground( );

            e.DrawBorder( );
            using (StringFormat sf = new StringFormat( ))
            {
                sf.Alignment     = StringAlignment.Center;
                sf.LineAlignment = StringAlignment.Center;
                sf.HotkeyPrefix  = System.Drawing.Text.HotkeyPrefix.None;
                sf.FormatFlags   = StringFormatFlags.NoWrap;

                using (Font f = new Font("宋体", 12))
                {
                    //e.Graphics.DrawString(e.ToolTipText, f,SystemBrushes.ActiveCaptionText, e.Bounds, sf);
                    e.Graphics.DrawString(e.ToolTipText, f, SystemBrushes.FromSystemColor(Color.Blue), e.Bounds, sf);
                }
            }
        }
Esempio n. 24
0
        protected override void DrawTabStrip(Graphics g)
        {
            CalculateTabs();

            Rectangle rectTabStrip = GetTabStripRectangle();

            if (rectTabStrip.IsEmpty)
            {
                return;
            }

            // Paint the background
            g.FillRectangle(SystemBrushes.FromSystemColor(SystemColors.ControlLightLight), rectTabStrip);
            g.DrawLine(SystemPens.ControlText, rectTabStrip.Left, rectTabStrip.Top,
                       rectTabStrip.Right, rectTabStrip.Top);

            for (int i = 0; i < CountOfVisibleContents; i++)
            {
                DrawTab(g, GetVisibleContent(i), GetTabRectangle(i));
            }
        }
Esempio n. 25
0
        /// <summary>
        /// Custom handler for drawing the tab text including Close X.
        /// </summary>
        /// <remarks>
        /// Location an dimensions of Close X must match with _tabControl_MouseDown logic.
        /// </remarks>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControl_DrawItem(object sender, DrawItemEventArgs e)
        {
            //This code will render a "x" mark at the end of the Tab caption.

            Font bold = new Font(e.Font.FontFamily, e.Font.Size + 1, FontStyle.Bold);

            #region Tab Background Color
            Brush backColorBrush = null;

            switch (e.State)
            {
            case DrawItemState.Selected:
                backColorBrush = SystemBrushes.ControlLightLight;
                break;

            default:
                backColorBrush = SystemBrushes.FromSystemColor(_tabControl.Parent.BackColor);
                break;
            }

            e.Graphics.FillRectangle(backColorBrush, e.Bounds);
            #endregion

            // Measure the tab text and if exceeds our max, then trim with ...
            SizeF s = e.Graphics.MeasureString(this._tabControl.TabPages[e.Index].Text, e.Font);

            //e.Bounds.Inflate(Convert.ToInt32(s.Width) + 50, 0);
            string text = this._tabControl.TabPages[e.Index].Text;
            if (s.Width > 80)
            {
                text = this._tabControl.TabPages[e.Index].Text.Substring(0, 10) + "...";
            }

            e.Graphics.DrawString("x", bold, Brushes.Black, e.Bounds.Right - 15, e.Bounds.Top + 1);
            e.Graphics.DrawString(text,
                                  e.Font, Brushes.Black, e.Bounds.Left + 7, e.Bounds.Top + 4);

            e.DrawFocusRectangle();
        }
Esempio n. 26
0
        private void Form1_Paint(object sender,
                                 System.Windows.Forms.PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            // Create a pen using SystemPens
            Pen pn = SystemPens.FromSystemColor(
                SystemColors.HotTrack);
            // Create a brush using SystemBrushes
            SolidBrush brush =
                (SolidBrush)SystemBrushes.FromSystemColor
                    (SystemColors.ActiveCaption);

            // Draw lines and rectangles
            g.DrawLine(pn, 20, 20, 20, 100);
            g.DrawLine(pn, 20, 20, 100, 20);
            g.FillRectangle(brush, 30, 30, 50, 50);
            // YOU CAN'T DISPOSE System pens AND
            // brushes. IF YOU TRY, GDI+ WILL GENERATE
            // AN ERROR
            //pn.Dispose();
            //brush.Dispose();
        }
Esempio n. 27
0
        protected override void DrawComboBoxItem(Graphics g, Rectangle bounds, int Index,
                                                 bool selected, bool editSel)
        {
            base.DrawComboBoxItem(g, bounds, Index, selected, editSel);

            if (Index != -1)
            {
                Brush brush = SystemBrushes.FromSystemColor(SystemColors.MenuText);

                Font currFont = new Font(Items[Index].ToString(), 10);

                Size textSize = TextUtil.GetTextSize(g, Items[Index].ToString(), currFont);
                int  top      = bounds.Top + (bounds.Height - textSize.Height) / 2;

                g.DrawImage(m_imgTTF, 1, top, bounds.Height - 1, bounds.Height - 1);

                g.DrawString(Items[Index].ToString(), currFont, brush,
                             new Point(bounds.Left + 1 + bounds.Height, top));

                brush.Dispose();
            }
        }
Esempio n. 28
0
        public override void LPaint(MarginBase x, MarginPaintEvent me)
        {
            int ip = me.line + P.LineOffset + 1;

            if (ip > 0 && ip <= (P as TextPanelBase).LinesAvail)
            {
                me.gfx.DrawString(
                    (ip).ToString(),
                    P.Font,
                    SystemBrushes.FromSystemColor(ForeColor),
                    4, me.line * P.Font.Height
                    );
            }
            else
            {
                me.gfx.DrawString(
                    (0).ToString(),
                    P.Font,
                    SystemBrushes.FromSystemColor(SystemColors.ButtonHighlight),
                    4, me.line * P.Font.Height
                    );
            }
        }
Esempio n. 29
0
        private void DrawTab(Graphics g, Content c, Rectangle rect)
        {
            Rectangle rectIcon = new Rectangle(
                rect.X + MeasureNormalTab.ImageGapLeft,
                rect.Y + rect.Height - 1 - MeasureNormalTab.ImageGapBottom - MeasureNormalTab.ImageHeight,
                MeasureNormalTab.ImageWidth, MeasureNormalTab.ImageHeight);
            Rectangle rectText = rectIcon;

            rectText.X    += rectIcon.Width + MeasureNormalTab.ImageGapRight;
            rectText.Width = rect.Width - rectIcon.Width - MeasureNormalTab.ImageGapLeft -
                             MeasureNormalTab.ImageGapRight - MeasureNormalTab.TextGapRight;

            if (ActiveContent == c)
            {
                g.FillRectangle(SystemBrushes.Control, rect);
                g.DrawLine(SystemPens.ControlText,
                           rect.X, rect.Y + rect.Height - 1, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
                g.DrawLine(SystemPens.ControlText,
                           rect.X + rect.Width - 1, rect.Y, rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
                g.DrawString(c.Text, Font, SystemBrushes.ControlText, rectText, StringFormatTab);
            }
            else
            {
                if (GetIndexOfVisibleContents(ActiveContent) !=
                    GetIndexOfVisibleContents(c) + 1)
                {
                    g.DrawLine(SystemPens.GrayText,
                               rect.X + rect.Width - 1, rect.Y + 3, rect.X + rect.Width - 1, rect.Y + rect.Height - 4);
                }
                g.DrawString(c.Text, Font, SystemBrushes.FromSystemColor(SystemColors.GrayText), rectText, StringFormatTab);
            }

            if (rect.Contains(rectIcon))
            {
                g.DrawIcon(c.Icon, rectIcon);
            }
        }
Esempio n. 30
0
        private void DrawTab(Graphics g, Content c, Rectangle rect)
        {
            Rectangle rectText = rect;

            rectText.X     += MeasureDocListTab.TextExtraWidth / 2;
            rectText.Width -= MeasureDocListTab.TextExtraWidth;
            if (ActiveContent == c)
            {
                g.FillRectangle(SystemBrushes.Control, rect);
                g.DrawLine(SystemPens.ControlText,
                           rect.X + rect.Width - 1, rect.Y,
                           rect.X + rect.Width - 1, rect.Y + rect.Height - 1);
                if (IsActivated)
                {
                    using (Font boldFont = new Font(this.Font, FontStyle.Bold))
                    {
                        g.DrawString(c.Text, boldFont, SystemBrushes.ControlText, rectText, StringFormatTab);
                    }
                }
                else
                {
                    g.DrawString(c.Text, Font, SystemBrushes.FromSystemColor(SystemColors.GrayText), rectText, StringFormatTab);
                }
            }
            else
            {
                if (GetIndexOfVisibleContents(ActiveContent) != GetIndexOfVisibleContents(c) + 1)
                {
                    g.DrawLine(SystemPens.GrayText,
                               rect.X + rect.Width - 1, rect.Y,
                               rect.X + rect.Width - 1, rect.Y + rect.Height - 1 - MeasureDocListTab.TabGapTop);
                }

                g.DrawString(c.Text, Font, SystemBrushes.FromSystemColor(SystemColors.GrayText), rectText, StringFormatTab);
            }
        }