Resolved GDI+, draw checkmark

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
How does the CheckBox control draw that black check mark in the white box? I can't install .Net Reflector or anything here on my work machine so could someone post the code (vb.net or c# is fine with me)?

Or if anyone knows how to do it (I have an 8x8 Bitmap object I'm drawing on already) I'd like a hand since my math isn't working out correctly:
VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.Controls.Add(New PictureBox With {.Location = New Point(5I, 5I), .SizeMode = PictureBoxSizeMode.AutoSize, .Image = GetCheckMark()})
    End Sub

    Private Function GetCheckMark() As Bitmap
        Dim HW As Integer = 96I 'Set to 96x96 to better see it during dev, needs to to be 8x8 on the destination control
        Dim bmp As New Bitmap(HW, HW)
        Using g As Graphics = Graphics.FromImage(bmp)
            Using WhiteBR As New SolidBrush(SystemColors.Window)
                g.FillRectangle(WhiteBR, New Rectangle(0I, 0I, HW, HW))
            End Using
            Dim pts(5I) As Point
            pts(0I) = New Point(0I, CInt(HW * (5I / 6I)))




            pts(1I) = New Point(CInt(HW * (1I / 3I)), CInt(HW * (3I / 4I)))
            pts(2I) = New Point(CInt(HW * (6I / 7I)), 4I)
            pts(3I) = New Point(CInt(HW * (6I / 7I)), 8I)
            pts(4I) = New Point(CInt(HW * (1I / 3I)), CInt(HW * (8I / 9I)))




            pts(5I) = New Point(3I, CInt(HW * (2I / 3I)))

            Using BlackBR As New SolidBrush(SystemColors.ControlText)
                g.FillPolygon(BlackBR, pts)
            End Using
            g.Save()
        End Using
        Return bmp
    End Function
End Class
 
I was playing with the CheckBoxRenderer class yesterday and I got it to work in the ListBox's OnDrawItem (on the correct item) but I wasn't able to have it draw it in the LB's Forecolor on the LB's backcolor, then jmc suggested I look at fonts, like Wingdings and there's on in there so I got it to work by using .DrawString() in that font.

I forgot to mark this thread as resolved last night.
 
Back
Top