'コントロールの宣言 Dim objTxtBox As TextBox Dim objBtn As Button Dim objLstBox As ListBox Dim objChkBox As CheckBox Dim objRadioBtn(1) As RadioButton Dim objLabel As Label
Private Sub Form1_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load
objTxtBox = New TextBox objBtn = New Button objLstBox = New ListBox objChkBox = New CheckBox objRadioBtn(0) = New RadioButton objRadioBtn(1) = New RadioButton objLabel = New Label
'コントロールの追加 With Me.Controls .Add(objBtn) .Add(objTxtBox) .Add(objLstBox) .Add(objChkBox) .Add(objRadioBtn(0)) .Add(objRadioBtn(1)) .Add(objLabel) End With
Private Sub objBtn_Name_Click(ByVal sender As Object, _ ByVal e As EventArgs) If objTxtBox.Text = "" Then MsgBox("文字列を入力して下さい") Exit Sub End If If objRadioBtn(0).Checked Then objLstBox.Items.Add(objTxtBox.Text) If objChkBox.Checked Then MsgBox("リストへ追加しました") End If
Else objLstBox.Items.Remove(objTxtBox.Text) If objChkBox.Checked Then MsgBox("リストから削除しました") End If End If End Sub