Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom Drawing - ButtonRenderer quality issue

Status
Not open for further replies.

Borvik

Programmer
Jan 2, 2002
1,392
0
0
US
Hello.

I'm having a quality issue while using the ButtonRenderer to draw a button. Really what I need is only HALF of the button, so I figured I could create an image (Bitmap) draw the button to it, and then draw the required half of the bitmap to my control. There are some quality issues that are very noticeable while the button is in the PRESSED state - that are not there when using the control's graphics object being passed to the ButtonRenderer.

Here's a piece of example code that will show what I've described:

Code:
    Private Sub pbox_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles pbox.Paint
        Dim lft As Integer = 15
        Dim top As Integer = 15

        For i As Integer = 1 To 5
            Dim btnBounds As New Rectangle(lft, top, 75, 23)
            ButtonRenderer.DrawButton(e.Graphics, btnBounds, i)
            top += 28
        Next

        top = 15
        lft += 80
        For i As Integer = 1 To 5
            Dim bmp As New Bitmap(75, 23)
            Dim g As Graphics = Graphics.FromImage(bmp)
            ButtonRenderer.DrawButton(g, New Rectangle(0, 0, 75, 23), i)
            g.Dispose()
            e.Graphics.DrawImage(bmp, lft, top)
            top += 28
        Next
    End Sub

This results in the following:
Examples.png


Column 1 shows the button drawn directly to the PictureBox's graphics object (as obtained from the eventargs), and column 2 shows the button drawn first to a bitmap and then the picturebox. The 3 row (pressed state) is the one that shows the quality issue the clearest - you can see the top corners are not nicely rounded when drawn to the bitmap first.

As far as I can figure I need to draw to the bitmap first so I can grab only the part of the button I actually need to display.

Anyone know how to resolve the quality issues I'm having with the bitmap drawing?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top