LoginSignup
0
0

cscの作法 その428

Last updated at Posted at 2023-08-24

概要

cscの作法、調べてみた。
RadioButton使ってみた。

写真

image.png

サンプルコード


using System;
using System.Drawing;
using System.Windows.Forms;

namespace App
{
	public class Form1: Form {
		private Label label;
		RadioButton radio1;
		RadioButton radio2;
		public Form1() {
			this.Width = 300;
			this.Height = 200;
			setupControls();
		}
		public void setupControls() {
			label = new Label();
			label.Text = "type text:";
			label.Font = new Font("Geneva", 12, FontStyle.Regular);
			label.Height = 30;
			label.Width = 300;
			this.Controls.Add(label);
			GroupBox group = new GroupBox();
			group.Width = 200;
			group.Height = 100;
			group.Top = 50;
			group.Left = 50;
			group.Text = "radio group";
			this.Controls.Add(group);
			radio1 = new RadioButton();
			radio1.Text = "male";
			radio1.Top = 25;
			radio1.Left = 25;
			radio1.Checked = true;
			radio1.CheckedChanged += check_changed;
			group.Controls.Add(radio1);
			radio2 = new RadioButton(); 
			radio2.Text = "fimale";
			radio2.Top = 50;
			radio2.Left = 25;
			radio2.CheckedChanged += check_changed;
			group.Controls.Add(radio2);
		}
		private void check_changed(object sender, System.EventArgs e) {
			RadioButton btn = (RadioButton) sender;
			label.Text = "selected: " + btn.Text;
		}
		[STAThread]
		static void Main() {
			Application.EnableVisualStyles();
			Application.SetCompatibleTextRenderingDefault(false);
			Application.Run(new Form1());
		}
	}
}





以上。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0