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

Posted at

概要

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

練習問題

メモ帳を書け。

写真

image.png

サンプルコード


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

namespace App
{
	public partial class Form1: Form {
		TextBox bo1;
		MenuStrip menuStrip1;
		ToolStripMenuItem openToolStripMenuItem;
		ToolStripMenuItem saveToolStripMenuItem;
		ToolStripMenuItem quitToolStripMenuItem;
		public Form1() {
			Text = "memo";
			ClientSize = new Size(500, 500);
			bo1 = new TextBox();
			bo1.Text = "本日は晴天なり";
			bo1.Multiline = true;
			bo1.Font = new Font("MS Pゴシック", 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();
			}
		}
		[STAThread]
		public static void Main(string[] args) {
			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?