Hey all,
I am changing the color of a checkbox tick square by creating a custom checkbox and painting over the box, and if the check state is checked, I then paint the check. The code below works but it seems a bit gludgy and I am wondering if there may be a better way.
The problem I'm having is finding the location of the tick box. If the checkbox.AutoSize=False and the user changes the height of the checkbox, sometimes the code I have fits the drawn rectangle perfectly, but sometime it's a pixel off and looks bad. Whether it fix or not depends on the height of the box and discrepancy is mostly likely because of rounding issues in math.
I am wondering if there is some other method to find the tick box directly? I know I can create an entirely new checkbox using a control, a label and the CheckBoxRenderer Class but that is a bit more work.
Any ideas?
thanks
kevin
I am changing the color of a checkbox tick square by creating a custom checkbox and painting over the box, and if the check state is checked, I then paint the check. The code below works but it seems a bit gludgy and I am wondering if there may be a better way.
vb Code:
Public Class myCheckBox Inherits CheckBox #Region "Properties" Private _tickColor As Color = Color.Yellow Public Property tickColor() As Color Get Return _tickColor End Get Set(ByVal value As Color) _tickColor = value End Set End Property #End Region Private Sub myCheckBox_Paint(sender As Object, e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint Const BOX_LEFT As Integer = 1 Const BOX_SIZE As Integer = 11 Dim boxTop As Integer = CInt(Me.Height / 2) - CInt(BOX_SIZE / 2) Dim r As New Rectangle(BOX_LEFT, boxTop, BOX_SIZE, BOX_SIZE) Dim br As New SolidBrush(_tickColor) e.Graphics.FillRectangle(br, r) If Me.Checked Then Const CHECK_TEXT As String = "" 'checkmark from the Wingdings font e.Graphics.DrawString(CHECK_TEXT, New Font("wingdings", Me.Font.Size), Brushes.Black, New Point(1, boxTop)) End If End Sub End Class
I am wondering if there is some other method to find the tick box directly? I know I can create an entirely new checkbox using a control, a label and the CheckBoxRenderer Class but that is a bit more work.
Any ideas?
thanks
kevin