'//----------------------------------------------------------------------
'//【ビッグラジオボタン・コントロール】- BigRadioButton
'//
'//
'//                                                       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(BigRadioButton), "BigRadioButtonToolbox.bmp")> _
Public Class BigRadioButton : Inherits RadioButton
  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(BigRadioButton), "RadioMark.png")
  End Sub
  '//
  '// Dispose
  '//
  Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    If disposing Then
    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
    'オプションマークの描画
    If Me.Checked Then
      ControlPaint.DrawRadioButton(e.Graphics, New Rectangle(0, 0, Me.Height, Me.Height), ButtonState.Checked)
      e.Graphics.DrawImage(img, CInt(Me.Height / 20 * 4), CInt(Me.Height / 20 * 4), CInt(Me.Height / 20 * 12), CInt(Me.Height / 20 * 12))
    Else
      ControlPaint.DrawRadioButton(e.Graphics, New Rectangle(0, 0, Me.Height, Me.Height), ButtonState.Normal)
    End If
    'テキストの描画
    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

