Make checkbox larger

  • Thread starter Thread starter TS
  • Start date Start date
T

TS

Who knows how to make the actual check box rectangle larger? Is the onlyway
to inherit from checkbox and override its paint method or something?

thanks
 
Hi TS,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to make the check box
rectangle larger. If there is any misunderstanding, please feel free to let
me know.

Yes, you're right. There is no direct way to achieve this by setting a
property or something like that. The only way is to override its paint
method. But I think this is not easy.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
TS said:
Who knows how to make the actual check box rectangle
larger? Is the onlyway to inherit from checkbox and override its
paint method or something?

Yes.

Very quick and dirty:

\\\
Option Explicit On
Option Strict On

Public Class CheckBoxEx
Inherits System.Windows.Forms.CheckBox

Private Sub CheckBoxEx_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs _
) Handles MyBase.Paint
Dim rct As Rectangle = _
New Rectangle( _
0, _
CInt((Me.Height - Me.Font.Size) * 0.5), _
CInt(Me.Font.Size), CInt(Me.Font.Size) _
)
e.Graphics.FillRectangle( _
Brushes.Black, _
New Rectangle(0, 0, Me.Width, Me.Height) _
)
Select Case Me.CheckState
Case CheckState.Checked
e.Graphics.FillRectangle(Brushes.Red, rct)
Case CheckState.Indeterminate
e.Graphics.FillRectangle(Brushes.Green, rct)
Case CheckState.Unchecked
e.Graphics.FillRectangle(Brushes.Blue, rct)
End Select
Dim ForeBrush As New SolidBrush(Me.ForeColor)
e.Graphics.DrawString( _
Me.Text, _
Me.Font, _
ForeBrush, _
CInt(Me.Font.Size + 4), _
CInt((Me.Height - Me.Font.Size) * 0.5) _
)
ForeBrush.Dispse()
End Sub

Private Sub CheckBoxEx_CheckStateChanged( _
ByVal sender As Object, _
ByVal e As System.EventArgs _
) Handles MyBase.CheckStateChanged
Me.Invalidate()
End Sub
End Class
///
 
You could create your own control fairly easily and then use the
ControlPaint.DrawCheckBox method to draw one of a specific size. The
standard size is discovered in the SystemInformation.MenuCheckSize property.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml
 
Hi TS,

Nice to hear that you have had this issue resolved. Thanks for sharing your
experience with all the people here. If you have any questions, please feel
free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top