source code:
Notepaper.cs:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace C7Tray
{
public partial class Notepaper : Form
{
public Notepaper()
{
InitializeComponent();
}
private void Notepaper_Load(object sender, EventArgs e)
{
this.Opacity = 0.7;
append.Visible = false;
}
private Point mouseOffset;
private string path;
#region Drag=Down+Move
private void Notepaper_MouseDown(object sender, MouseEventArgs e)
{
mouseOffset = new Point(e.X, e.Y);
}
private void Notepaper_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Right)
{
Point newPostion = new Point(Control.MousePosition.X - mouseOffset.X, Control.MousePosition.Y - mouseOffset.Y);
this.Location = newPostion;
}
}
#endregion
private void save_Click(object sender, EventArgs e) //Save&Creat the text.....
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
path = saveFileDialog.FileName;
File.WriteAllText(path, textBox.Text);
}
catch (IOException ex)
{
MessageBox.Show(ex.Message, "Crazy7-Notepaper", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
Point savePos = save.Location; //Very "Ben" idea....
append.Location = savePos;
append.Visible = true;
}
private void append_Click(object sender, EventArgs e) //Append text
{
File.WriteAllText(path, textBox.Text);
}
private void newNote_Click(object sender, EventArgs e) //New Note
{
Notepaper another = new Notepaper();
another.Show();
}
private void upOpacity_Click(object sender, EventArgs e) //up the transparence
{
this.Opacity -= 0.1;
}
private void downOpacity_Click(object sender, EventArgs e) //down the transparence
{
this.Opacity += 0.1;
}
private void Notepaper_FormClosing(object sender, FormClosingEventArgs e)
{
if (textBox.Text!=""&&append.Visible==true) //Auto save
{
File.WriteAllText(path, textBox.Text);
}
}
}
}
Notepaper.Designer.cs:
namespace C7Tray
{
partial class Notepaper
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.save = new System.Windows.Forms.Button();
this.textBox = new System.Windows.Forms.TextBox();
this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.append = new System.Windows.Forms.Button();
this.upOpacity = new System.Windows.Forms.Button();
this.downOpacity = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.newNote = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// save
//
this.save.Location = new System.Drawing.Point(3, 203);
this.save.Name = "save";
this.save.Size = new System.Drawing.Size(53, 23);
this.save.TabIndex = 1;
this.save.Text = "&Save";
this.save.UseVisualStyleBackColor = true;
this.save.Click += new System.EventHandler(this.save_Click);
//
// textBox
//
this.textBox.Location = new System.Drawing.Point(3, 0);
this.textBox.Multiline = true;
this.textBox.Name = "textBox";
this.textBox.Size = new System.Drawing.Size(276, 187);
this.textBox.TabIndex = 0;
//
// saveFileDialog
//
this.saveFileDialog.Filter = "Text Files|*.txt";
//
// append
//
this.append.Location = new System.Drawing.Point(12, 174);
this.append.Name = "append";
this.append.Size = new System.Drawing.Size(53, 23);
this.append.TabIndex = 2;
this.append.Text = "&Save";
this.append.UseVisualStyleBackColor = true;
this.append.Click += new System.EventHandler(this.append_Click);
//
// upOpacity
//
this.upOpacity.Location = new System.Drawing.Point(169, 203);
this.upOpacity.Name = "upOpacity";
this.upOpacity.Size = new System.Drawing.Size(47, 23);
this.upOpacity.TabIndex = 3;
this.upOpacity.Text = "UP";
this.upOpacity.UseVisualStyleBackColor = true;
this.upOpacity.Click += new System.EventHandler(this.upOpacity_Click);
//
// downOpacity
//
this.downOpacity.Location = new System.Drawing.Point(225, 203);
this.downOpacity.Name = "downOpacity";
this.downOpacity.Size = new System.Drawing.Size(47, 23);
this.downOpacity.TabIndex = 4;
this.downOpacity.Text = "Down";
this.downOpacity.UseVisualStyleBackColor = true;
this.downOpacity.Click += new System.EventHandler(this.downOpacity_Click);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(166, 187);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(75, 13);
this.label1.TabIndex = 5;
this.label1.Text = "transparence:";
//
// newNote
//
this.newNote.Location = new System.Drawing.Point(62, 203);
this.newNote.Name = "newNote";
this.newNote.Size = new System.Drawing.Size(50, 23);
this.newNote.TabIndex = 6;
this.newNote.Text = "New";
this.newNote.UseVisualStyleBackColor = true;
this.newNote.Click += new System.EventHandler(this.newNote_Click);
//
// Notepaper
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(276, 238);
this.Controls.Add(this.newNote);
this.Controls.Add(this.label1);
this.Controls.Add(this.downOpacity);
this.Controls.Add(this.upOpacity);
this.Controls.Add(this.append);
this.Controls.Add(this.textBox);
this.Controls.Add(this.save);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.Name = "Notepaper";
this.Text = "Crazy7-Notepaper";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.Notepaper_FormClosing);
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Notepaper_MouseMove);
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Notepaper_MouseDown);
this.Load += new System.EventHandler(this.Notepaper_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Button save;
private System.Windows.Forms.TextBox textBox;
private System.Windows.Forms.SaveFileDialog saveFileDialog;
private System.Windows.Forms.Button append;
private System.Windows.Forms.Button upOpacity;
private System.Windows.Forms.Button downOpacity;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button newNote;
}
}