下のドロップダウンフォームには、ユーザーが C1DropDownControl から選択を行うためのオプションボタンとボタンコントロールが含まれています。
ドロップダウンフォームの外観プロパティは、フォームが次のように表示されるように既に編集されています。
C1DropDownControl の DropDownFormClassName プロパティで、フォームのクラス名(この例では、WindowsApplication1.DropDownForm1)を選択します。プロジェクトを実行してドロップダウン矢印を選択すると、ドロップダウンフォームが表示されます。
Visual Basicでコードを書く場合
| Visual Basic |
コードのコピー
|
|---|---|
Private Sub DropDownForm1_PostChanges(sender As Object, e As System.EventArgs)
If (MyBase.DialogResult = DialogResult.OK) Then
Dim control1 As Control
For Each control1 In MyBase.Controls
If (TypeOf control1 is RadioButton AndAlso CType(control1, RadioButton).Checked) Then
MyBase.OwnerControl.Value = CType(control1, RadioButton).Text
End If
Next
End If
End Sub
|
|
C#でコードを書く場合
| C# |
コードのコピー
|
|---|---|
private void DropDownForm1_PostChanges(object sender, System.EventArgs e)
{
if (DialogResult == DialogResult.OK)
{
foreach (Control control1 in Controls)
{
if (control1 as RadioButton != null && ((RadioButton)control1).Checked)
{
OwnerControl.Value = ((RadioButton)control1).Text;
}
}
}
}
|
|
をクリックします。
フォームは次のように表示されます。