Public Class radbtn
Const pointx As Integer = 0 'PictureBox1の左上の位置
Const pointy As Integer = 0 'PictureBox1の左上の位置
Private _sze As Integer 'PictureBox1のサイズ
Private _str As String 'RadioButtonのラベルの文字
Private _bool As Boolean 'ボタンの描画メソッドで取得した値
>
'PictureBox1のSizeの書き込み
Public Property sze() As Integer
Get
Return _sze
End Get
Set(value As Integer)
_sze = value
End Set
End Property
'ラベルの文字を書き込む
Public Property str() As String
Get
Return _str
End Get
Set(value As String)
_str = value
End Set
End Property
'ボタンの状態を読み込む
Public ReadOnly Property bool() As Boolean
Get
Return _bool
End Get
End Property
'RadioButton3文字描画
Public Sub strprint(ByVal txtsp As Bitmap)
Dim fnt As Font = New Font("MSゴシック", 18, FontStyle.Bold)
Dim gr As Graphics = Graphics.FromImage(txtsp)
gr.DrawString(" " & _str, fnt, Brushes.Black, 0, 0)
gr.Dispose()
End Sub
'初期状態のボタンの描画
Public Sub fast(ByVal sp1 As Bitmap)
gfile(sp1, "\rad1.jpg")
End Sub
'MouseDownのボタンの描画
Public Sub mousdown(ByVal sp2 As Bitmap, ByVal ex As Integer, ByVal ey As Integer)
gfile(sp2, "\rad2.jpg")
End Sub
'MouseUpのボタンの描画
Public Sub mousup(ByVal sp3 As Bitmap, ByVal ex As Integer, ByVal ey As Integer)
gfile(sp3, "\rad3.jpg")
End Sub
'ボタンの描画メソッド
Private Sub gfile(ByVal sp As Bitmap, ByVal pas As String)
'ボタンの状態をBoolean値にする
If pas = "\rad1.jpg" Then
_bool = False
ElseIf pas = "\rad3.jpg" Then
_bool = True
End If
'ボタンの2重線を描画するための色と太さ
Dim pn As New Pen(Brushes.Black, 1)
'gをGraphics型にしてImageを代入
Dim g As Graphics = Graphics.FromImage(sp)
'Imageをファイルから取得
Dim img As Image = Image.FromFile(Application.StartupPath & pas)
'ボタンの画像 + 3 - 7はボタンの外径より画像を小さくするため
g.DrawImage(img, pointx + 3, pointy + 3, _sze - 7, _sze - 7)
'ボタンの外枠 - 1ボタンのが径がPictureBoxと同じだと接点が綺麗に描画されません
g.DrawEllipse(pn, pointx, pointy, _sze - 1, _sze - 1)
'ボタンの内枠
g.DrawEllipse(pn, pointx + 3, pointy + 3, _sze - 7, _sze - 7)
g.Dispose()
End Sub
End Class
|