LoginSignup
1
0

More than 1 year has passed since last update.

cscの作法 その182

Posted at

概要

cscの作法、調べてみた。
練習問題やってみた。

練習問題

湯婆婆を実装せよ。

サンプルコード

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Globalization;

class form1: Form {
	TextBox bo1;
	TextBox bo2;
	public form1() {
		this.Text = "ybb";
		this.ClientSize = new Size(400, 250);
		Button btn1 = new Button();
		btn1.Location = new Point(250, 200);
		btn1.Text = "承諾";
		btn1.Click += btn1_Click;
		Controls.AddRange(new Control[] {
			btn1
		});
		bo1 = new TextBox();
		bo1.Location = new Point(50, 30);
		bo1.Width = 300;
		bo1.Height = 100;
		bo1.Multiline = true;
		bo1.Text += "契約書\r\n";
		bo1.Text += "甲は油屋当主として、乙を油屋に雇用することを契約し、\r\n";
		bo1.Text += "労働に伴う対価の支払いを右の通り、約定する。\r\n";
		bo1.Text += "なお、一日の労働の対価は金百円とする。\r\n";
		bo1.Text += "甲 油屋当主 湯婆婆\r\n";
		bo1.Text += "\r\n";
		bo1.Text += "乙\r\n";
		Controls.AddRange(new Control[] {
			bo1
		});
		bo2 = new TextBox();
		bo2.Location = new Point(150, 130);
		bo2.Width = 100;
		bo2.Height = 30;
		bo2.Text = "吉田恵子";
		Controls.AddRange(new Control[] {
			bo2
		});
	}
	void btn1_Click(object sender, System.EventArgs e) {
		string str = "契約書だよ。そこに名前を書きな。";
		string name = bo2.Text;
		str += String.Format("フン。{0}というのかい。贅沢な名だねぇ。", name);
		Random random = new Random();
		StringInfo nameInfo = new StringInfo(name);
		int newNameIndex = random.Next(nameInfo.LengthInTextElements);
		string newName = nameInfo.SubstringByTextElements(newNameIndex, 1);
		str += String.Format("今からお前の名前は{0}だ。いいかい、{0}だよ。分かったら返事をするんだ、{0}!!", newName);
		MessageBox.Show(str);
	}
	[STAThread]
	public static void Main() {
		Application.Run(new form1());
	}
}





以上。

1
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
1
0