Results 1 to 3 of 3

Thread: [RESOLVED] ToolStrip Split Button - Custom highlight Color not drawing the Arrow

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    482

    Resolved [RESOLVED] ToolStrip Split Button - Custom highlight Color not drawing the Arrow

    I am using a custom renderer to change the highlilght color dor a ToolStrip Split button (code below). It works and the highlighted color is indeed changed, the problem is when highlighted it does not draw the arrow. I have tried calling MyBase.MyBase.OnRenderArrow() and also MyBase.DrawArrow() but neither seems to draw the arrow. Maybe I am creating the graphics object incorrectly or something.

    This works fine, and the arrow is drawn on a plain ToolStrip DropDownButton but just not the Split button for some reason.

    Any other suggestions to get the arrow drawn from a custom renderer?
    Why is the Arrow not getting drawn in the first place?

    vb.net Code:
    1. Private Class MyRenderer : Inherits ToolStripProfessionalRenderer
    2.    Protected Overrides Sub OnRenderSplitButtonBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
    3.      If e.Item.Selected Then
    4.         Dim rc As New Rectangle(Point.Empty, e.Item.Size)
    5.         'Set the highlight color
    6.         e.Graphics.FillRectangle(Brushes.Gainsboro, rc)
    7.         e.Graphics.DrawRectangle(Pens.Gainsboro, 1, 0, rc.Width - 2, rc.Height - 1)
    8.     Else
    9.        MyBase.OnRenderSplitButtonBackground(e)
    10.     End If
    11.   End Sub
    12.     End Class

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,344

    Re: ToolStrip Split Button - Custom highlight Color not drawing the Arrow

    As you didn't show us what you did, it's hard to know exactly what you did wrong, which is exactly why you should ALWAYS shows us what you did. I would assume that you did not correctly create the ToolStripArrowRenderEventArgs object required by both OnRenderArrow and DrawArrow. Both methods worked for me when I created it like this:
    vb.net Code:
    1. Dim tsrea = New ToolStripArrowRenderEventArgs(e.Graphics,
    2.                                               e.Item,
    3.                                               DirectCast(e.Item, ToolStripSplitButton).DropDownButtonBounds,
    4.                                               Color.Black,
    5.                                               ArrowDirection.Down)

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    482

    Re: ToolStrip Split Button - Custom highlight Color not drawing the Arrow

    Quote Originally Posted by jmcilhinney View Post
    As you didn't show us what you did, it's hard to know exactly what you did wrong, which is exactly why you should ALWAYS shows us what you did. I would assume that you did not correctly create the ToolStripArrowRenderEventArgs object required by both OnRenderArrow and DrawArrow. Both methods worked for me when I created it like this:
    vb.net Code:
    1. Dim tsrea = New ToolStripArrowRenderEventArgs(e.Graphics,
    2.                                               e.Item,
    3.                                               DirectCast(e.Item, ToolStripSplitButton).DropDownButtonBounds,
    4.                                               Color.Black,
    5.                                               ArrowDirection.Down)
    I actually got it working last night, but it was really late so I didn't post back here. In the end, I had everything the same as yours but I was manually calculating the rectangle (shown below). I have now changed to the DirectCast as in your example. Much cleaner. Thanks!!!

    vb.net Code:
    1. Dim pb As RectangleF = i.Image.GetBounds(GraphicsUnit.Pixel) 'pb is the rectangle for the image
    2.                 Dim bb As Rectangle = i.Bounds                                          'bb is the rectangle for the whole button
    3.                 Dim l As Integer = bb.X + pb.Width + 5                                'Left
    4.                 Dim t As Integer = pb.Y                                                     'Top
    5.                 Dim w As Integer = (bb.Width - pb.Width) - 5                       'Width
    6.                 Dim h = bb.Height                                                            'Height
    7.                 Dim r As Rectangle = New Rectangle(l, t, w, h)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width