Check the box according to the size of the box?

Introduction

I am writing a simple custom checkbox element that will draw a background and checkmark in a custom color.

To draw a checkmark, I do this:

    ''' <summary>
    ''' Draws the checkbox tick.
    ''' </summary>
    ''' <param name="g">The drawing surface.</param>
    ''' <param name="rect">The box rectangle.</param>
    ''' <param name="checkState">The checkbox state.</param>
    Private Sub DrawTick(ByVal g As Graphics,
                         ByVal rect As Rectangle,
                         ByVal checkState As CheckState)

        Select Case checkState

            Case checkState.Checked

                Dim points As PointF() =
                    New PointF() {
                        New PointF(rect.X + 3, rect.Y + 5),
                        New PointF(rect.X + 5, rect.Y + 7),
                        New PointF(rect.X + 9, rect.Y + 3),
                        New PointF(rect.X + 9, rect.Y + 4),
                        New PointF(rect.X + 5, rect.Y + 8),
                        New PointF(rect.X + 3, rect.Y + 6),
                        New PointF(rect.X + 3, rect.Y + 7),
                        New PointF(rect.X + 5, rect.Y + 9),
                        New PointF(rect.X + 9, rect.Y + 5)
                    }

                Using checkPen As New Pen(Me.TickColor, 1)
                    g.DrawLines(checkPen, points)
                End Using

            Case checkState.Indeterminate

                Using checkBrush As New SolidBrush(Me.TickColor)

                    g.FillRectangle(checkBrush, New Rectangle(rect.X + 3,
                                                              rect.Y + 3,
                                                              rect.Width - 5,
                                                              rect.Height - 5))
                End Using

            Case checkState.Unchecked
                ' Do Nothing.

        End Select

    End Sub

This is the result:

enter image description here


Problem

The problem is that the size / tick points are indicated according to the default field size, I get the main idea from this article:

True Transparency Support for .NET CheckBox Control

So, let's say I increase the check box (width and height rectvar of the above code), then it will draw a tiny tick like this:

enter image description here


Question

How could I dynamically change the arithmetic that I do with the points in the method DrawTickto fix the tick size for other box sizes?

+4
1

, , "x" "y". ( , 12 , ):

    Dim scaleFactor As Single = CType(rect.Width, Single) / 12.0
    Dim points As PointF() =
        New PointF() {
            New PointF(rect.X + scaleFactor * 3, rect.Y + scaleFactor * 5),
            New PointF(rect.X + scaleFactor * 5, rect.Y + scaleFactor * 7),
            New PointF(rect.X + scaleFactor * 9, rect.Y + scaleFactor * 3),
            New PointF(rect.X + scaleFactor * 9, rect.Y + scaleFactor * 4),
            New PointF(rect.X + scaleFactor * 5, rect.Y + scaleFactor * 8),
            New PointF(rect.X + scaleFactor * 3, rect.Y + scaleFactor * 6),
            New PointF(rect.X + scaleFactor * 3, rect.Y + scaleFactor * 7),
            New PointF(rect.X + scaleFactor * 5, rect.Y + scaleFactor * 9),
            New PointF(rect.X + scaleFactor * 9, rect.Y + scaleFactor * 5)
        }
+2

All Articles