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;
}
}
}
}