2. thời gian chạy. Nó phức tạp hơn một chút so với phương pháp trên. Trong phương pháp này, bạn có thể tạo một RadioButton theo chương trình với sự trợ giúp của lớp RadioButton. Các bước sau đây cho thấy cách tạo một RadioButton động
- Bước 1. Tạo nút radio bằng hàm tạo RadioButton[] được cung cấp bởi lớp RadioButton
// Creating radio button RadioButton r1 = new RadioButton[];
- Bước 2. Sau khi tạo RadioButton, thiết lập các thuộc tính của RadioButton do lớp RadioButton cung cấp
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];
- Bước 3. Và cuối cùng thêm điều khiển RadioButton này vào biểu mẫu bằng phương thức Add[]
// Add this radio button to the form this.Controls.Add[r1];
- Ví dụ
CSharp
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];7
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];9
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];1
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];0
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];2
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];4
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];8
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];6
// Add this radio button to the form this.Controls.Add[r1];0
// Add this radio button to the form this.Controls.Add[r1];1
// Add this radio button to the form this.Controls.Add[r1];2
// Add this radio button to the form this.Controls.Add[r1];3
// Add this radio button to the form this.Controls.Add[r1];4
// Add this radio button to the form this.Controls.Add[r1];5
// Add this radio button to the form this.Controls.Add[r1];6
// Add this radio button to the form this.Controls.Add[r1];7____23
// Add this radio button to the form this.Controls.Add[r1];9
// Add this radio button to the form this.Controls.Add[r1];7____461
_______462____463
// Add this radio button to the form this.Controls.Add[r1];7____465
// Add this radio button to the form this.Controls.Add[r1];7__
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];67
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];68
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];69
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];70
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];71
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];72
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];73
// Add this radio button to the form this.Controls.Add[r1];7____461
// Add this radio button to the form this.Controls.Add[r1];7____465
// Add this radio button to the form this.Controls.Add[r1];7______467
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];68
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];61
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];70
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];63
// Add this radio button to the form this.Controls.Add[r1];7____461
_______462____467
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______469____490
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];91
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____493____494
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____497______490
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];99
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____461____462
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______465
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];90
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];67
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];68
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];69
_______462____511
_______462____513____514
_______462____516
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____518
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____460____490
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62
_______462____464____494
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
_______462____468____469
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
________ 462 ________ 102 ________ 490 ________ 104
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______106
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];90
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];67
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];68
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];69
_______462____511
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____513____115
_______462____516
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____518
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____121____490
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____125____494
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
_______462____129____130
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];33
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];90
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];35
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______137
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];90
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];67
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];68
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];69
_______462____511
_______462____513____146
_______462____516
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____518
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______152____490
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____156____494
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____160____161
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];95
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______164____490
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];66
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62______168
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];90
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];67
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];68
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];69
_______462____511
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];62____513____177
// Add this radio button to the form this.Controls.Add[r1];7____465
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];65
// Set the AutoSize property r1.AutoSize = true; // Add text in RadioButton r1.Text = "Intern"; // Set the location of the RadioButton r1.Location = new Point[286, 40]; // Set Font property r1.Font = new Font["Berlin Sans FB", 12];65
- đầu ra.
Thuộc tính quan trọng
radiobutton-table { border-collapse. sự sụp đổ; . 100%; . radiobutton-table td { đường viền. 1px cố định #5fb962; . trái. quan trọng; . 8px; . radiobutton-table thứ { đường viền. 1px cố định #5fb962; . 8px; . radiobutton-table tr>th{ màu nền. #c6ebd9; . tên đệm; . radiobutton-bảng tr. con thứ n[lẻ] { màu nền. #ffffff;