cscの作法 その555

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

# 練習問題
forth電卓とメモ帳をドッキングせよ。

# 写真

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/18104/28397d7d-cf47-fee8-177d-e35efaddecef.png)


# サンプルコード

```




using WeifenLuo.WinFormsUI.Docking;
using System.ComponentModel;
using System;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;

namespace Dock
{
	public partial class Win2: WeifenLuo.WinFormsUI.Docking.DockContent {
		Button btn0;
		Button btn1;
		Button btn2;
		Button btn3;
		Button btn4;
		Button btn5;
		Button btn6;
		Button btn7;
		Button btn8;
		Button btn9;
		Button btn10;
		Button btn11;
		Button btn12;
		Button btn13;
		Button btn14;
		Button btn15;
		Button btn16;
		Button btn17;
		string v;
		Label label;
		private static Stack<int> stack = new Stack<int>();
		public Win2() {
			ClientSize = new Size(260, 260);
			Text = "forth電卓";
			InitializeComponent();
			v = "";
		}
		private void InitializeComponent() {
			label = new Label();
			label.Text = "0";
			label.Font = new Font("Geneva", 20, FontStyle.Regular);
			label.BackColor = Color.Azure;
			label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			label.Dock = DockStyle.Fill;
			TableLayoutPanel parent = new TableLayoutPanel();
			parent.Width = 250;
			parent.Height = 250;
			parent.ColumnCount = 4;
			parent.RowCount = 6;
			for (int i = 0; i < parent.RowCount; i++)
			{
				parent.RowStyles.Add(new RowStyle() {
					Height = 20,
					SizeType = SizeType.Percent
				});
			}
			for (int j = 0; j < parent.ColumnCount; j++)
			{
				parent.ColumnStyles.Add(new ColumnStyle() {
					Width = 25,
					SizeType = SizeType.Percent
				});
			}
			this.Controls.Add(parent);
			Control childControl;
			btn0 = new Button();
			btn0.Click += new System.EventHandler(btn0_Click);
			btn0.Text = "Clear";
			btn0.Dock = DockStyle.Fill;
			parent.Controls.Add(btn0);
			btn1 = new Button();
			btn1.Click += new System.EventHandler(btn1_Click);
			btn1.Text = "/";
			btn1.Dock = DockStyle.Fill;
			parent.Controls.Add(btn1);
			btn2 = new Button();
			btn2.Click += new System.EventHandler(btn2_Click);
			btn2.Text = "*";
			btn2.Dock = DockStyle.Fill;
			parent.Controls.Add(btn2);
			btn3 = new Button();
			btn3.Click += new System.EventHandler(btn3_Click);
			btn3.Text = "-";
			btn3.Dock = DockStyle.Fill;
			parent.Controls.Add(btn3);
			btn4 = new Button();
			btn4.Click += new System.EventHandler(btn4_Click);
			btn4.Text = "7";
			btn4.Dock = DockStyle.Fill;
			parent.Controls.Add(btn4);
			btn5 = new Button();
			btn5.Click += new System.EventHandler(btn5_Click);
			btn5.Text = "8";
			btn5.Dock = DockStyle.Fill;
			parent.Controls.Add(btn5);
			btn6 = new Button();
			btn6.Click += new System.EventHandler(btn6_Click);
			btn6.Text = "9";
			btn6.Dock = DockStyle.Fill;
			parent.Controls.Add(btn6);
			btn7 = new Button();
			btn7.Click += new System.EventHandler(btn7_Click);
			btn7.Text = "+";
			btn7.Dock = DockStyle.Fill;
			parent.Controls.Add(btn7);
			childControl = parent.GetControlFromPosition(3, 1);
			parent.SetRowSpan(childControl, 2);
			btn8 = new Button();
			btn8.Click += new System.EventHandler(btn8_Click);
			btn8.Text = "4";
			btn8.Dock = DockStyle.Fill;
			parent.Controls.Add(btn8);
			btn9 = new Button();
			btn9.Click += new System.EventHandler(btn9_Click);
			btn9.Text = "5";
			btn9.Dock = DockStyle.Fill;
			parent.Controls.Add(btn9);
			btn10 = new Button();
			btn10.Click += new System.EventHandler(btn10_Click);
			btn10.Text = "6";
			btn10.Dock = DockStyle.Fill;
			parent.Controls.Add(btn10);
			btn11 = new Button();
			btn11.Click += new System.EventHandler(btn11_Click);
			btn11.Text = "1";
			btn11.Dock = DockStyle.Fill;
			parent.Controls.Add(btn11);
			btn12 = new Button();
			btn12.Click += new System.EventHandler(btn12_Click);
			btn12.Text = "2";
			btn12.Dock = DockStyle.Fill;
			parent.Controls.Add(btn12);
			btn13 = new Button();
			btn13.Click += new System.EventHandler(btn13_Click);
			btn13.Text = "3";
			btn13.Dock = DockStyle.Fill;
			parent.Controls.Add(btn13);
			btn14 = new Button();
			btn14.Click += new System.EventHandler(btn14_Click);
			btn14.Text = ".";
			btn14.Dock = DockStyle.Fill;
			parent.Controls.Add(btn14);
			childControl = parent.GetControlFromPosition(3, 3);
			parent.SetRowSpan(childControl, 2);
			btn15 = new Button();
			btn15.Click += new System.EventHandler(btn15_Click);
			btn15.Text = "0";
			btn15.Dock = DockStyle.Fill;
			parent.Controls.Add(btn15);
			btn16 = new Button();
			btn16.Click += new System.EventHandler(btn16_Click);
			btn16.Text = "dup";
			btn16.Dock = DockStyle.Fill;
			parent.Controls.Add(btn16);
			btn17 = new Button();
			btn17.Click += new System.EventHandler(btn16_Click);
			btn17.Text = "drop";
			btn17.Dock = DockStyle.Fill;
			parent.Controls.Add(btn17);
			parent.Controls.Add(label);
			childControl = parent.GetControlFromPosition(0, 5);
			parent.SetColumnSpan(childControl, 3);
		}
		private void btn0_Click(object sender, EventArgs e) {//clear
			v = "";
			label.Text = v;
			stack = new Stack<int>();
		}
		private void btn1_Click(object sender, EventArgs e) {///
			v = "";
			div();
		}
		private void btn2_Click(object sender, EventArgs e) {//*
			v = "";
			mul();
		}
		private void btn3_Click(object sender, EventArgs e) {//-
			v = "";
			sub();
		}
		private void btn4_Click(object sender, EventArgs e) {//7
			v = "7";
			push(v);
			label.Text = v;
		}
		private void btn5_Click(object sender, EventArgs e) {//8
			v = "8";
			push(v);
			label.Text = v;
		}
		private void btn6_Click(object sender, EventArgs e) {//9
			v = "9";
			push(v);
			label.Text = v;
		}
		private void btn7_Click(object sender, EventArgs e) {//+
			v = "";
			add();
		}
		private void btn8_Click(object sender, EventArgs e) {//4
			v = "4";
			push(v);
			label.Text = v;
		}
		private void btn9_Click(object sender, EventArgs e) {//5
			v = "5";
			push(v);
			label.Text = v;
		}
		private void btn10_Click(object sender, EventArgs e) {//6
			v = "6";
			push(v);
			label.Text = v;
		}
		private void btn11_Click(object sender, EventArgs e) {//1
			v = "1";
			push(v);
			label.Text = v;
		}
		private void btn12_Click(object sender, EventArgs e) {//2
			v = "2";
			push(v);
			label.Text = v;
		}
		private void btn13_Click(object sender, EventArgs e) {//3
			v = "3";
			push(v);
			label.Text = v;
		}
		private void btn14_Click(object sender, EventArgs e) {//.
			int top1 = stack.Pop();
			label.Text = top1.ToString();
		}
		private void btn15_Click(object sender, EventArgs e) {//0
			v = "0";
			push(v);
			label.Text = v;
		}
		private void btn16_Click(object sender, EventArgs e) {//dup
			dup();
			int top1 = stack.Pop();
			label.Text = top1.ToString();
		}
		private void btn17_Click(object sender, EventArgs e) {//drop
			drop();
			int top1 = stack.Pop();
			label.Text = top1.ToString();
		}
		private void add() {
			int top1 = stack.Pop();
			int top2 = stack.Pop();
			int v = top2 + top1;
			stack.Push(v);
		}
		private void sub() {
			int top1 = stack.Pop();
			int top2 = stack.Pop();
			int v = top2 - top1;
			stack.Push(v);
		}
		private void mul() {
			int top1 = stack.Pop();
			int top2 = stack.Pop();
			int v = top2 * top1;
			stack.Push(v);
		}
		private void div() {
			int top1 = stack.Pop();
			int top2 = stack.Pop();
			int v = top2 / top1;
			stack.Push(v);
		}
		private void dup() {
			int top1 = stack.Pop();
			stack.Push(top1);
			stack.Push(top1);
		}
		private void drop() {
			int top1 = stack.Pop();
		}
		private void push(string s) {
			int v = Convert.ToInt32(s);
			stack.Push(v);
		}
	}
	public partial class Win1: WeifenLuo.WinFormsUI.Docking.DockContent {
		TextBox bo1;
		MenuStrip menuStrip1;
		ToolStripMenuItem openToolStripMenuItem;
		ToolStripMenuItem saveToolStripMenuItem;
		ToolStripMenuItem quitToolStripMenuItem;
		public Win1() {
			Text = "memo";
			ClientSize = new Size(500, 500);
			bo1 = new TextBox();
			bo1.Text = @"9を4個使って1から15で求める式
9を4個使う	答え
9 9 - 9 9 / .	1
9 9 / 9 9 / + .	2
9 9 + 9 + 9 / .	3
9 9 9 + 9 / dup + .	4
9 9 9 + 9 / dup + - .	5
9 dup 9 + 9 + 9 / - .	6
9 9 9 + 9 / - .	7
9 9 9 drop 9 / - .	8
9 9 - 9 * 9 + .	9
9 9 / 9 dup 9 / + .	10
9 9 9 + 9 / + .	11
9 dup 9 9 + + 9 / + .	12
9 9 9 + 9 / dup + + .	13
9 dup 9 9 + 9 / dup + - + .	14
9 dup dup 9 + 9 + 9 / - + .	15
";
			bo1.Multiline = true;
			bo1.Font = new Font("ＭＳ Ｐゴシック", 12);
			bo1.Dock = DockStyle.Fill;
			this.menuStrip1 = new MenuStrip();
			this.menuStrip1.Location = new Point(0, 0);
			this.menuStrip1.Name = "menu";
			this.menuStrip1.Size = new Size(353, 24);
			this.menuStrip1.TabIndex = 1;
			this.menuStrip1.Text = "menu";
			this.openToolStripMenuItem = new ToolStripMenuItem();
			this.openToolStripMenuItem.Name = "open";
			this.openToolStripMenuItem.Text = "open";
			this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
			this.saveToolStripMenuItem = new ToolStripMenuItem();
			this.saveToolStripMenuItem.Name = "save";
			this.saveToolStripMenuItem.Text = "save";
			this.saveToolStripMenuItem.Click += new System.EventHandler(this.saveToolStripMenuItem_Click);
			this.quitToolStripMenuItem = new ToolStripMenuItem();
			this.quitToolStripMenuItem.Name = "quit";
			this.quitToolStripMenuItem.Text = "quit";
			this.quitToolStripMenuItem.Click += new System.EventHandler(this.quitToolStripMenuItem_Click);
			this.menuStrip1.Items.AddRange(new ToolStripItem[] {
				this.openToolStripMenuItem,
				this.saveToolStripMenuItem,
				this.quitToolStripMenuItem
			});
			Controls.AddRange(new Control[] {
				bo1,
				menuStrip1
			});
		}
		private void openToolStripMenuItem_Click(object sender, EventArgs e) {
			OpenFileDialog dialog = new OpenFileDialog();
			dialog.Filter = "テキストファイル(*.txt)|*.txt";
			dialog.Title = "開く";
			if (dialog.ShowDialog() == DialogResult.OK)
				bo1.Text = File.ReadAllText(dialog.FileName, Encoding.GetEncoding("UTF-8"));
		}
		private void saveToolStripMenuItem_Click(object sender, EventArgs e) {
			SaveFileDialog dialog = new SaveFileDialog();
			dialog.Filter = "テキストファイル(*.txt)|*.txt";
			dialog.Title = "保存";
			if (dialog.ShowDialog() == DialogResult.OK)
			{
				File.WriteAllText(dialog.FileName, bo1.Text);
			}
		}
		private void quitToolStripMenuItem_Click(object sender, EventArgs e) {
			DialogResult result = MessageBox.Show("メモ帳を終了します", "終了", MessageBoxButtons.YesNo);
			if (result == DialogResult.Yes)
			{
				Close();
			}
		}
	}
	public partial class Win3: WeifenLuo.WinFormsUI.Docking.DockContent {
		public Win3() {
		}
	}
	public partial class Win4: WeifenLuo.WinFormsUI.Docking.DockContent {
		public Win4() {
		}
	}
	public partial class MainForm: Form {
		DockPanel dockPanel1 = new DockPanel();
		public MainForm() {
			ClientSize = new Size(900, 500);
			dockPanel1.ShowDocumentIcon = true;
			dockPanel1.Dock = DockStyle.Fill;
			dockPanel1.DocumentStyle = DocumentStyle.DockingWindow;
			Controls.Add(dockPanel1);
			Win1 win1 = new Win1();
			win1.Show(dockPanel1, DockState.DockRight);
			Win2 win2 = new Win2();
			win2.Show(dockPanel1, DockState.Document);
			Win3 win3 = new Win3();
			win3.Show(dockPanel1, DockState.DockLeft);
			Win4 win4 = new Win4();
			win4.Show(dockPanel1, DockState.DockBottom);
		}
		[STAThread]
		public static void Main(string[] args) {
			Application.Run(new MainForm());
		}
	}
}




```

以上。