'//----------------------------------------------------------------------
'//【ビッグチェックボックス・コントロール】- BigCheckBox
'//
'//
'//                                                       by Masato Hirai         
'//----------------------------------------------------------------------
Imports System
Imports System.Drawing
Imports System.Drawing.Text
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports System.ComponentModel

<ToolboxBitmap(GetType(BigCheckBox), "BigCheckBoxToolbox.bmp")> _
Public Class BigCheckBox : Inherits CheckBox
  Private img As Bitmap
  '//
  '// コンストラクタ
  '//
  Public Sub New()
    MyBase.New()
    Me.SetStyle(ControlStyles.ResizeRedraw _
             Or ControlStyles.Opaque _
             Or ControlStyles.AllPaintingInWmPaint _
             Or ControlStyles.UserPaint _
             Or ControlStyles.DoubleBuffer, True)
    img = New Bitmap(GetType(BigCheckBox), "CheckMark.png")
  End Sub
  '//
  '// Dispose
  '//
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
      If Not (img Is Nothing) Then img.Dispose()
    End If
    MyBase.Dispose(disposing)
  End Sub
  '//
  '// OnPaint イベント
  '//
  Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    '背景の描画
    MyBase.OnPaintBackground(e)
    'フォーカス時の選択枠の描画
    If Me.Focused Then
      Dim r As Rectangle = Me.ClientRectangle
      r.X = Me.Height * 1.05
      r.Y = 0
      r.Height = Me.Height
      r.Width = Me.Width - r.X
      ControlPaint.DrawFocusRectangle(e.Graphics, r)
    End If
    'チェックマークの描画
    Dim rc As New Rectangle(0, 0, Me.Height, Me.Height)
    Select Case Me.CheckState
      Case CheckState.Checked
        ControlPaint.DrawCheckBox(e.Graphics, rc, ButtonState.Normal)
        e.Graphics.DrawImage(img, 0, 0, Me.Height, Me.Height)
      Case CheckState.Indeterminate
        ControlPaint.DrawCheckBox(e.Graphics, rc, ButtonState.Inactive)
      Case CheckState.Unchecked
        ControlPaint.DrawCheckBox(e.Graphics, rc, ButtonState.Normal)
    End Select
    'テキストの描画
    Dim fmt As New StringFormat
    fmt.LineAlignment = StringAlignment.Center
    e.Graphics.DrawString(Me.Text, Me.Font, _
      New SolidBrush(Me.ForeColor), _
      Me.Height * 1.1, Me.Height \ 2, fmt)
  End Sub

End Class
