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の作法 その553

Last updated at Posted at 2025-02-09

概要

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

練習問題

window formでドッキングウィンドウを実現せよ。

手順

いつものFormを、DockContentに変換するだけ。凄い。

写真

スクリーンショット 2025-02-09 104107.png

サンプルコード

using System;
using System.Data;
using System.Linq;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using System.Drawing;
using System.Globalization;

namespace Dock
{
	public partial class Win2: WeifenLuo.WinFormsUI.Docking.DockContent {
		public Win2() {
			Text = "じゃんけん";
			ClientSize = new Size(200, 200);
			Button btn1 = new Button();
			btn1.Location = new Point(30, 30);
			btn1.Text = "グー";
			btn1.Click += btn1_Click;
			Button btn2 = new Button();
			btn2.Location = new Point(30, 80);
			btn2.Text = "チョキ";
			btn2.Click += btn2_Click;
			Button btn3 = new Button();
			btn3.Location = new Point(30, 130);
			btn3.Text = "パー";
			btn3.Click += btn3_Click;
			Controls.AddRange(new Control[] {
				btn1,
				btn2,
				btn3,
			});
		}
		void btn1_Click(object sender, System.EventArgs e) {
			string b = "2";
			string name = "012";
			Random random = new Random();
			StringInfo nameInfo = new StringInfo(name);
			int newNameIndex = random.Next(nameInfo.LengthInTextElements);
			b = nameInfo.SubstringByTextElements(newNameIndex, 1);
			string str = "";
			switch (b)
			{
			case "0":
				str = "グーとグーで、あいこ";
			break;
			case "1":
				str = "グーとチョキで、あなたの勝ち";
			break;
			case "2":
				str = "グーとパーで、あなたの負け";
			break;
			default:
			break;
			}
			MessageBox.Show(str);
		}
		void btn2_Click(object sender, System.EventArgs e) {
			string b = "2";
			string name = "012";
			Random random = new Random();
			StringInfo nameInfo = new StringInfo(name);
			int newNameIndex = random.Next(nameInfo.LengthInTextElements);
			b = nameInfo.SubstringByTextElements(newNameIndex, 1);
			string str = "";
			switch (b)
			{
			case "0":
				str = "チョキとグーで、あなたの負け";
			break;
			case "1":
				str = "チョキとチョキで、あいこ";
			break;
			case "2":
				str = "チョキとパーで、あなたの勝ち";
			break;
			default:
			break;
			}
			MessageBox.Show(str);
		}
		void btn3_Click(object sender, System.EventArgs e) {
			string b = "2";
			string name = "012";
			Random random = new Random();
			StringInfo nameInfo = new StringInfo(name);
			int newNameIndex = random.Next(nameInfo.LengthInTextElements);
			b = nameInfo.SubstringByTextElements(newNameIndex, 1);
			string str = "";
			switch (b)
			{
			case "0":
				str = "パーとグーで、あなたの勝ち";
			break;
			case "1":
				str = "パーとチョキで、あなたの負け";
			break;
			case "2":
				str = "パーとパーで、あいこ";
			break;
			default:
			break;
			}
			MessageBox.Show(str);
		}
	}
	public partial class Win1: WeifenLuo.WinFormsUI.Docking.DockContent {
		public Win1() {
		}
	}
	public partial class Form1: Form {
		public Form1() {
			ClientSize = new Size(900, 600);
			Text = "dock";
			Test1();
		}
		private void Test1() {
			var dockPanel1 = new DockPanel();
			dockPanel1.ShowDocumentIcon = true;
			dockPanel1.Dock = DockStyle.Fill;
			dockPanel1.DocumentStyle = DocumentStyle.DockingWindow;
			Controls.Add(dockPanel1);
			var left1 = new Win1();
			left1.TabText = "left1";
			left1.Show(dockPanel1, DockState.DockLeft);
			var right1 = new Win1();
			right1.TabText = "right1";
			right1.Show(dockPanel1, DockState.DockRight);
			var bottom1 = new Win1();
			bottom1.TabText = "bottom1";
			bottom1.Show(dockPanel1, DockState.DockBottom);
			var center1 = new Win2();
			center1.TabText = "center1";
			center1.Show(dockPanel1, DockState.Document);
		}
		[STAThread]
		public static void Main() {
			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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?