0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

cscの作法 その639

0
Posted at

概要

cscの作法、調べてみた。
数値入力inbox書いてみた。

写真

image.png

サンプルコード





using System;
using System.Windows.Forms;
using System.Text;
using System.IO;
using System.Drawing;

namespace App
{
	public partial class SubForm: Form {
		NumericUpDown numericUpDown1;
		public int InputValue {
			get;
		private set;
		}
		public SubForm() {
			Text = "数値入力";
			Button btnOK = new Button();
			btnOK.Location = new Point(60, 160);
			btnOK.Text = "OK";
			btnOK.Click += btnOK_Click;
			Button btnCancel = new Button();
			btnCancel.Location = new Point(160, 160);
			btnCancel.Text = "CANCEL";
			numericUpDown1 = new NumericUpDown();
			numericUpDown1.Minimum = 100;
			numericUpDown1.Maximum = 200;
			numericUpDown1.Value = 150;
			numericUpDown1.Location = new Point(80, 40);
			Controls.AddRange(new Control[] {
				btnOK,
				btnCancel,
				numericUpDown1
			});
			btnOK.DialogResult = DialogResult.OK;
			btnCancel.DialogResult = DialogResult.Cancel;
			this.AcceptButton = btnOK;
			this.CancelButton = btnCancel;
		}
		private void btnOK_Click(object sender, EventArgs e) {
			InputValue = (int) numericUpDown1.Value; 
		}
	}
	public partial class MainForm: Form {
		public MainForm() {
			Text = "数値入力";
			Button btn1 = new Button();
			btn1.Location = new Point(80, 100);
			btn1.Text = "数値入力";
			btn1.Click += btn1_Click;
			Controls.AddRange(new Control[] {
				btn1
			});
		}
		private void btn1_Click(object sender, EventArgs e) {
			using (SubForm subForm = new SubForm())
			{
				if (subForm.ShowDialog() == DialogResult.OK)
				{
					int result = subForm.InputValue;
					MessageBox.Show(string.Format("入力された数値は{0}です。", result), "結果");
				}
				else
				{
					MessageBox.Show("入力をキャンセルしました。", "通知");
				}
			}
		}
		[STAThread]
		public static void Main() {
			Application.Run(new MainForm());
		}
	}
}




以上。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?