Delphi radiobutton
时间: 2023-10-28 19:04:35 浏览: 147
Delphi中的RadioButton是一种Windows控件,它允许用户在一组选项中选择一个选项。以下是创建和使用RadioButton的一些示例代码:
1. 创建一个RadioButton:
```Delphi
var
RadioButton1: TRadioButton;
begin
RadioButton1 := TRadioButton.Create(Form1);
RadioButton1.Parent := Form1;
RadioButton1.Caption := 'Option 1';
RadioButton1.Left := 10;
RadioButton1.Top := 10;
RadioButton1.Checked := True;
end;
```
2. 处理RadioButton的CheckedChanged事件:
```Delphi
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
if RadioButton1.Checked then
ShowMessage('Option 1 selected');
end;
```
3. 以组的形式使用RadioButton:
```Delphi
var
GroupBox1: TGroupBox;
RadioButton1, RadioButton2, RadioButton3: TRadioButton;
begin
GroupBox1 := TGroupBox.Create(Form1);
GroupBox1.Parent := Form1;
GroupBox1.Caption := 'Options';
GroupBox1.Left := 10;
GroupBox1.Top := 10;
RadioButton1 := TRadioButton.Create(GroupBox1);
RadioButton1.Parent := GroupBox1;
RadioButton1.Caption := 'Option 1';
RadioButton1.Left := 10;
RadioButton1.Top := 20;
RadioButton1.Checked := True;
RadioButton2 := TRadioButton.Create(GroupBox1);
RadioButton2.Parent := GroupBox1;
RadioButton2.Caption := 'Option 2';
RadioButton2.Left := 10;
RadioButton2.Top := 40;
RadioButton3 := TRadioButton.Create(GroupBox1);
RadioButton3.Parent := GroupBox1;
RadioButton3.Caption := 'Option 3';
RadioButton3.Left := 10;
RadioButton3.Top := 60;
end;
```
这些代码演示了如何创建、处理和以组的形式使用RadioButton。你可以根据需要进行更改和扩展。
阅读全文
相关推荐















