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

More than 1 year has passed since last update.

cscの作法 その461

Last updated at Posted at 2024-03-01

概要

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

練習問題

ボタンが一個だけのForm

写真

image.png

サンプルコード

using System;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;

namespace App
{
	public class Form1: Form {
		Button button1;
		private NotifyIcon notifyIcon1;
		private ContextMenu contextMenu1;
		private MenuItem menuItem1;
		private IContainer components;
		public Form1() {
			this.Text = "test";
			this.StartPosition = FormStartPosition.Manual;
			this.BackColor = Color.Red;
			this.Size = new Size(100, 100);
			this.Location = new Point(1000, 100);
			button1 = new Button();
			button1.Location = new Point(20, 20);
			button1.Text = "test";
			button1.BackColor = Color.Aqua;
			button1.Click += new EventHandler(button1_Click);
			this.Controls.Add(button1);
			this.Shown += new System.EventHandler(this.Form1_Shown);
			this.components = new Container();
			this.contextMenu1 = new ContextMenu();
			this.menuItem1 = new MenuItem();
			this.contextMenu1.MenuItems.AddRange(new MenuItem[] {
				this.menuItem1
			});
			this.menuItem1.Index = 0;
			this.menuItem1.Text = "E&xit";
			this.menuItem1.Click += new EventHandler(this.menuItem1_Click);
			this.notifyIcon1 = new NotifyIcon(this.components);
			notifyIcon1.Icon = new Icon("dolphin.ico");
			notifyIcon1.ContextMenu = this.contextMenu1;
			notifyIcon1.Text = "Form1 (NotifyIcon example)";
			notifyIcon1.Visible = true;
			notifyIcon1.DoubleClick += new EventHandler(this.notifyIcon1_DoubleClick);
		}
		private void button1_Click(object sender, EventArgs e) {
			MessageBox.Show("ok");
		}
		protected override void Dispose(bool disposing) {
			if (disposing)
				if (components != null)
					components.Dispose();
			base.Dispose(disposing);
		}
		private void notifyIcon1_DoubleClick(object Sender, EventArgs e) {
			if (this.WindowState == FormWindowState.Minimized)
				this.WindowState = FormWindowState.Normal;
			this.Activate();
		}
		private void menuItem1_Click(object Sender, EventArgs e) {
			this.Close();
		}
		private void Form1_Shown(object sender, EventArgs e) {
			FormBorderStyle = FormBorderStyle.None;
			this.TransparencyKey = this.BackColor;
		}
		[STAThread]
		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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?