概要
cscの作法、調べてみた。
練習問題、やってみた。
練習問題
ボタンが一個だけのForm
写真
サンプルコード
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());
}
}
}
以上