以下は未使用。
Program.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
using System; using System.Windows.Forms; namespace sticker_notes { static class Program { /// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> [STAThread] static void Main() { //Application.EnableVisualStyles(); //Application.SetCompatibleTextRenderingDefault(false); NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Visible = true; ni.Icon = new System.Drawing.Icon(@"C:\Program Files\Windows Live\Writer\writer.ico");//適当なico ni.Click += new EventHandler((object sender, EventArgs e) => { Form1 f = new Form1(); f.Show(); }); ni.DoubleClick += new EventHandler((object sender, EventArgs e)=> { Application.Exit(); }); Application.Run(); } } } |
Form1.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
using System; using System.Drawing; using System.Windows.Forms; namespace sticker_notes { public partial class Form1 : Form { int mouseX; int mouseY; int mouseWith; int mouseHeight; Boolean FgWith = false; Boolean FgHeight = false; public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; //バーは消えるがサイズ変更できず。 //this.ControlBox = false; //this.Text = ""; //サイズ変更できるが境界線が消せない。 this.Opacity = 0.9; this.TopMost = true; TextBox tb = new System.Windows.Forms.TextBox(); tb.Dock = DockStyle.Fill; tb.Multiline = true; tb.Font = new Font("", 12); tb.BackColor = Color.Beige; this.Controls.Add(tb); tb.KeyDown += new KeyEventHandler(this.text_keydown); tb.MouseDown += new MouseEventHandler(this.mouse_down); tb.MouseMove += new MouseEventHandler(this.mouse_move); tb.MouseUp += new MouseEventHandler(this.mouse_up); } public void mouse_up(object sender, MouseEventArgs e) { FgWith = false; FgHeight = false; } public void mouse_down(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.mouseX = e.X; this.mouseY = e.Y; this.mouseWith = this.Width; this.mouseHeight = this.Height; } } public void mouse_move(object sender, MouseEventArgs e) { if (e.X > this.Width - 20 && e.X < this.Width && e.Y > this.Height - 20 && e.Y < this.Height && !FgWith && !FgHeight) { this.Cursor = Cursors.SizeNWSE; if (e.Button == MouseButtons.Left) { FgWith = true; FgHeight = true; } } else if (e.X > this.Width - 20 && e.X < this.Width && !FgHeight) { this.Cursor = Cursors.SizeWE; if (e.Button == MouseButtons.Left) FgWith = true; } else if (e.Y > this.Height - 20 && e.Y < this.Height && !FgWith) { this.Cursor = Cursors.SizeNS; if (e.Button == MouseButtons.Left) FgHeight = true; } if (FgWith && FgHeight && e.Button == MouseButtons.Left) { this.Width = mouseWith + e.X - this.mouseX; this.Height = mouseHeight + e.Y - this.mouseY; } else if (FgWith && e.Button == MouseButtons.Left) { this.Width = mouseWith + e.X - this.mouseX; } else if (FgHeight && e.Button == MouseButtons.Left) { this.Height = mouseHeight + e.Y - this.mouseY; } else if (!FgWith && !FgHeight && e.Button == MouseButtons.Left) { this.Left += e.X - this.mouseX; this.Top += e.Y - this.mouseY; } } public void text_keydown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Escape) this.Close(); if (e.Control && e.KeyCode == Keys.A) (sender as TextBox).SelectAll(); } } } |
画像の場合
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using System.Windows.Forms; namespace sticker_notes { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; PictureBox tb = new PictureBox(); tb.ImageLocation = Application.StartupPath + @"\1.jpg"; tb.Dock = DockStyle.Fill; tb.SizeMode = PictureBoxSizeMode.Zoom; this.Controls.Add(tb); } } } |
ここまで未使用。
サイズ変更の作りがおかしかったので、以下、修正版。画像を表示しておくため位置をxmlにシリアライズ。
Progam.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
using System; using System.Windows.Forms; namespace sticker_notes { static class Program { /// <summary> /// アプリケーションのメイン エントリ ポイントです。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); NotifyIcon ni = new System.Windows.Forms.NotifyIcon(); ni.Visible = true; ni.Icon = new System.Drawing.Icon(Application.StartupPath + @"\i.ico"); ni.DoubleClick += new EventHandler((object sender, EventArgs e) => { Application.Exit(); }); Form1 f = new Form1(); f.Show(); Application.Run(); } } } |
Form1.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
using System; using System.Drawing; using System.Windows.Forms; namespace sticker_notes { public partial class Form1 : Form { int MouseX; int MouseY; int ThisW; int ThisH; Boolean FW = false; Boolean FH = false; public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.Opacity = 0.9; this.TopMost = false; this.ShowInTaskbar = false; PictureBox pb = new PictureBox(); pb.Dock = DockStyle.Fill; pb.ImageLocation = Application.StartupPath + @"\1.jpg"; pb.SizeMode = PictureBoxSizeMode.Zoom; this.Controls.Add(pb); pb.MouseUp += new MouseEventHandler(this.mouse_up); pb.MouseDown += new MouseEventHandler(this.mouse_down); pb.MouseMove += new MouseEventHandler(this.mouse_move); StartPosition = FormStartPosition.Manual; try { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(int[])); using (System.IO.StreamReader sr = new System.IO.StreamReader(Application.StartupPath + @"\config", new System.Text.UTF8Encoding(false))) { int[] i = (int[])xs.Deserialize(sr); this.Width = i[0]; this.Height = i[1]; this.Top = i[2]; this.Left = i[3]; sr.Close(); } } catch (System.IO.FileNotFoundException e) { } } public void mouse_up(object sender, MouseEventArgs e) { FW = false; FH = false; System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(int[])); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\config",false,new System.Text.UTF8Encoding(false))) { xs.Serialize(sw, new int[] { this.Width, this.Height, this.Top, this.Left }); sw.Close(); } } public void mouse_down(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) return; this.MouseX = e.X; this.MouseY = e.Y; this.ThisW = this.Width; this.ThisH = this.Height; if (e.X > this.Width - 20 && e.X < this.Width && e.Y > this.Height - 20 && e.Y < this.Height) { FW = true; FH = true; } else if (e.X > this.Width - 20 && e.X < this.Width) { FW = true; } else if (e.Y > this.Height - 20 && e.Y < this.Height) { FH = true; } } public void mouse_move(object sender, MouseEventArgs e) { if (e.X > this.Width - 20 && e.X < this.Width && e.Y > this.Height - 20 && e.Y < this.Height) { this.Cursor = Cursors.SizeNWSE; } else if (e.X > this.Width - 20 && e.X < this.Width) { this.Cursor = Cursors.SizeWE; } else if (e.Y > this.Height - 20 && e.Y < this.Height) { this.Cursor = Cursors.SizeNS; } else { this.Cursor = Cursors.Default; } if (FW && FH) { this.Width = this.ThisW + e.X - this.MouseX; this.Height = this.ThisH + e.Y - this.MouseY; } else if (FW) { this.Width = ThisW + e.X - this.MouseX; } else if (FH) { this.Height = ThisH + e.Y - this.MouseY; } if (!FW && !FH && e.Button == MouseButtons.Left) { this.Left += e.X - this.MouseX; this.Top += e.Y - this.MouseY; } } } } |
これでデスクトップに画像を表示しておくことができる。
以下はテキスト用にForm1だけさらに修正。デスクトップに表示させておいてメモとして利用
Form1.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
using System; using System.Drawing; using System.Windows.Forms; namespace sticker_notes { public partial class Form1 : Form { int MouseX; int MouseY; int ThisW; int ThisH; Boolean FW = false; Boolean FH = false; Boolean Ctr = false; public Form1() { InitializeComponent(); this.FormBorderStyle = FormBorderStyle.None; this.Opacity = 0.9; this.TopMost = false; this.ShowInTaskbar = false; StartPosition = FormStartPosition.Manual; TextBox tb = new TextBox(); tb.Dock = DockStyle.Fill; tb.Multiline = true; tb.Font = new Font("メイリオ", 12); this.Controls.Add(tb); //tb.BackColor = Color.Transparent; //this.TransparencyKey = Color.White; try { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(int[])); using (System.IO.StreamReader sr = new System.IO.StreamReader(Application.StartupPath + @"\config", new System.Text.UTF8Encoding(false))) { int[] i = (int[])xs.Deserialize(sr); this.Width = i[0]; this.Height = i[1]; this.Top = i[2]; this.Left = i[3]; sr.Close(); } System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); xd.PreserveWhitespace = true; xd.Load(Application.StartupPath + @"\body"); xs = new System.Xml.Serialization.XmlSerializer(typeof(string)); using (System.Xml.XmlNodeReader xnr = new System.Xml.XmlNodeReader(xd.DocumentElement)) { tb.Text = (string)xs.Deserialize(xnr); xnr.Close(); } } catch (System.IO.FileNotFoundException e) { } tb.MouseUp += new MouseEventHandler(this.mouse_up); tb.MouseDown += new MouseEventHandler(this.mouse_down); tb.MouseMove += new MouseEventHandler(this.mouse_move); tb.TextChanged += new EventHandler(this.body_save); tb.KeyDown += new KeyEventHandler((object sender, KeyEventArgs e) => { if (e.Control && e.KeyCode == Keys.A) tb.SelectAll(); if (e.KeyCode == Keys.Escape) Application.Exit(); if (e.Control) Ctr = true; }); tb.KeyUp += new KeyEventHandler((object sender, KeyEventArgs e) => { Ctr = false; }); tb.GotFocus += new EventHandler((object sender, EventArgs e) => { this.Opacity = 0.9; }); tb.LostFocus += new EventHandler((object sender, EventArgs e) => { this.Opacity = 0.5; }); } public void body_save(object sender, EventArgs e) { System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(String)); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\body", false, new System.Text.UTF8Encoding(false))) { xs.Serialize(sw, ((TextBox)sender).Text); sw.Close(); } } public void mouse_up(object sender, MouseEventArgs e) { FW = false; FH = false; System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(int[])); using (System.IO.StreamWriter sw = new System.IO.StreamWriter(Application.StartupPath + @"\config",false,new System.Text.UTF8Encoding(false))) { xs.Serialize(sw, new int[] { this.Width, this.Height, this.Top, this.Left }); sw.Close(); } } public void mouse_down(object sender, MouseEventArgs e) { if (e.Button != MouseButtons.Left) return; this.MouseX = e.X; this.MouseY = e.Y; this.ThisW = this.Width; this.ThisH = this.Height; if (e.X > this.Width - 20 && e.X < this.Width && e.Y > this.Height - 20 && e.Y < this.Height) { FW = true; FH = true; } else if (e.X > this.Width - 20 && e.X < this.Width) { FW = true; } else if (e.Y > this.Height - 20 && e.Y < this.Height) { FH = true; } } public void mouse_move(object sender, MouseEventArgs e) { if (e.X > this.Width - 20 && e.X < this.Width && e.Y > this.Height - 20 && e.Y < this.Height) { this.Cursor = Cursors.SizeNWSE; } else if (e.X > this.Width - 20 && e.X < this.Width) { this.Cursor = Cursors.SizeWE; } else if (e.Y > this.Height - 20 && e.Y < this.Height) { this.Cursor = Cursors.SizeNS; } if (FW && FH) { this.Width = this.ThisW + e.X - this.MouseX; this.Height = this.ThisH + e.Y - this.MouseY; } else if (FW) { this.Width = ThisW + e.X - this.MouseX; } else if (FH) { this.Height = ThisH + e.Y - this.MouseY; } if (!FW && !FH && e.Button == MouseButtons.Left && Ctr) { this.Left += e.X - this.MouseX; this.Top += e.Y - this.MouseY; } } } } |