随手做了一个比较简单的(文件部分还没弄好,错啦~~,另外,还没做查找替换功能的,这个很简单啦,在反白显示中设置RichTextBox对象的Select方法就可以了,第一个参数是起始位置,第二个是长度)
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace Out
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
bool press = false;
bool press2 = false;
int x=0,y=0,x2=0,y2=0;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Panel panel4;
private System.Windows.Forms.RichTextBox TBox;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.Splitter splitter1;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TOD Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.splitter1 = new System.Windows.Forms.Splitter();
this.panel3 = new System.Windows.Forms.Panel();
this.panel4 = new System.Windows.Forms.Panel();
this.TBox = new System.Windows.Forms.RichTextBox();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5,
this.menuItem1,
this.menuItem9,
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem6,
this.menuItem7,
this.menuItem11,
this.menuItem8,
this.menuItem10});
//
// menuItem5
//
this.menuItem5.Checked = true;
this.menuItem5.Index = 0;
this.menuItem5.Text = "只读";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Text = "最大化";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// menuItem9
//
this.menuItem9.Index = 2;
this.menuItem9.Text = "还原";
this.menuItem9.Click += new System.EventHandler(this.menuItem9_Click);
//
// menuItem2
//
this.menuItem2.Index = 3;
this.menuItem2.Text = "最小化";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 4;
this.menuItem3.MergeOrder = 1;
this.menuItem3.Text = "通知图标";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 5;
this.menuItem4.Text = "全选";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem6
//
this.menuItem6.Index = 6;
this.menuItem6.Text = "设置选中字体";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// menuItem7
//
this.menuItem7.Index = 7;
this.menuItem7.Text = "设置全部字体";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem11
//
this.menuItem11.Index = 8;
this.menuItem11.Text = "设置默认字体";
this.menuItem11.Click += new System.EventHandler(this.menuItem11_Click);
//
// menuItem8
//
this.menuItem8.Index = 9;
this.menuItem8.Text = "关闭";
this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem10
//
this.menuItem10.Index = 10;
this.menuItem10.Text = "打开文件";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
// notifyIcon1
//
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "Reader";
this.notifyIcon1.Click += new System.EventHandler(this.notifyIcon1_Click);
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(239)), ((System.Byte)(243)), ((System.Byte)(247)));
this.panel1.Dock = System.Windows.Forms.DockStyle.Left;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(6, 454);
this.panel1.TabIndex = 0;
//
// panel2
//
this.panel2.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(239)), ((System.Byte)(243)), ((System.Byte)(247)));
this.panel2.Controls.Add(this.splitter1);
this.panel2.Dock = System.Windows.Forms.DockStyle.Bottom;
this.panel2.Location = new System.Drawing.Point(6, 448);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(602, 6);
this.panel2.TabIndex = 1;
//
// splitter1
//
this.splitter1.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(239)), ((System.Byte)(243)), ((System.Byte)(247)));
this.splitter1.Cursor = System.Windows.Forms.Cursors.SizeNWSE;
this.splitter1.Dock = System.Windows.Forms.DockStyle.Right;
this.splitter1.Location = new System.Drawing.Point(596, 0);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(6, 6);
this.splitter1.TabIndex = 5;
this.splitter1.TabStop = false;
this.splitter1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.splitter1_MouseUp);
this.splitter1.MouseMove += new System.Windows.Forms.MouseEventHandler(this.splitter1_MouseMove);
this.splitter1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.splitter1_MouseDown);
//
// panel3
//
this.panel3.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(239)), ((System.Byte)(243)), ((System.Byte)(247)));
this.panel3.Dock = System.Windows.Forms.DockStyle.Right;
this.panel3.Location = new System.Drawing.Point(602, 0);
this.panel3.Name = "panel3";
this.panel3.Size = new System.Drawing.Size(6, 448);
this.panel3.TabIndex = 2;
//
// panel4
//
this.panel4.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(239)), ((System.Byte)(243)), ((System.Byte)(247)));
this.panel4.Dock = System.Windows.Forms.DockStyle.Top;
this.panel4.Location = new System.Drawing.Point(6, 0);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(596, 6);
this.panel4.TabIndex = 3;
this.panel4.MouseUp += new System.Windows.Forms.MouseEventHandler(this.panel4_MouseUp);
this.panel4.MouseMove += new System.Windows.Forms.MouseEventHandler(this.panel4_MouseMove);
this.panel4.MouseDown += new System.Windows.Forms.MouseEventHandler(this.panel4_MouseDown);
//
// TBox
//
this.TBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.TBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.TBox.ContextMenu = this.contextMenu1;
this.TBox.Location = new System.Drawing.Point(6, 8);
this.TBox.Name = "TBox";
this.TBox.ReadOnly = true;
this.TBox.Size = new System.Drawing.Size(596, 442);
this.TBox.TabIndex = 4;
this.TBox.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackColor = System.Drawing.SystemColors.ControlLightLight;
this.ClientSize = new System.Drawing.Size(608, 454);
this.Controls.Add(this.TBox);
this.Controls.Add(this.panel4);
this.Controls.Add(this.panel3);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "Form1";
this.Text = "Reader";
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
this.WindowState=FormWindowState.Maximized;
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
this.WindowState=FormWindowState.Minimized;
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
this.WindowState=FormWindowState.Minimized;
this.Hide();
notifyIcon1.Visible=true;
}
private void menuItem5_Click(object sender, System.EventArgs e)
{
if(menuItem5.Checked)
{
menuItem5.Checked=false;
}
else
{
menuItem5.Checked=true;
}
TBox.ReadOnly=menuItem5.Checked;
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
TBox.SelectAll();
}
private void notifyIcon1_Click(object sender, System.EventArgs e)
{
this.Show();
this.WindowState=FormWindowState.Normal;
notifyIcon1.Visible=false;
}
private void menuItem8_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void menuItem9_Click(object sender, System.EventArgs e)
{
this.WindowState=FormWindowState.Normal;
}
private void menuItem6_Click(object sender, System.EventArgs e)
{
FontDialog f = new FontDialog();
f.ShowApply=true;
f.ShowColor=true;
f.ShowEffects=true;
f.Apply+=new EventHandler(f_Apply);
if(f.ShowDialog()==DialogResult.OK)
{
TBox.SelectionColor=f.Color;
TBox.SelectionFont=f.Font;
}
}
private void f_Apply(object sender, EventArgs e)
{
FontDialog f = (FontDialog )sender;
TBox.SelectionColor=f.Color;
TBox.SelectionFont=f.Font;
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
FontDialog f = new FontDialog();
f.ShowApply=true;
f.ShowColor=true;
f.ShowEffects=true;
f.Apply+=new EventHandler(f_Apply2);
if(f.ShowDialog()==DialogResult.OK)
{
TBox.SelectAll();
TBox.SelectionColor=f.Color;
TBox.SelectionFont=f.Font;
TBox.SelectionLength=0;
}
}
private void f_Apply2(object sender, EventArgs e)
{
FontDialog f = (FontDialog )sender;
TBox.SelectAll();
TBox.SelectionColor=f.Color;
TBox.SelectionFont=f.Font;
TBox.SelectionLength=0;
}
private void menuItem10_Click(object sender, System.EventArgs e)
{
OpenFileDialog f = new OpenFileDialog();
f.Title="请选择要打开的文件";
if(f.ShowDialog()==DialogResult.OK)
{
Fill(f.FileName);
}
}
private void Fill(string FileName)
{
try
{
StreamReader r = new StreamReader(FileName);
string T =null;
this.Cursor=Cursors.WaitCursor;
this.TBox.Cursor=Cursors.WaitCursor;
while(r.Peek()!=-1)
{
T+=r.ReadToEnd();
}
TBox.Text=T;
this.Cursor=Cursors.Default;
this.TBox.Cursor=Cursors.Default;
}
catch(System.Exception)
{
MessageBox.Show("此文件不可读","错误",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
private void menuItem11_Click(object sender, System.EventArgs e)
{
FontDialog f = new FontDialog();
f.ShowApply=false;;
f.ShowColor=true;
f.ShowEffects=true;
if(f.ShowDialog()==DialogResult.OK)
{
TBox.Font=f.Font;
TBox.ForeColor=f.Color;
}
}
private void panel4_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
press = true;x=e.X;y=e.Y;
}
private void panel4_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
press = false;
}
private void panel4_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(!press)return;
this.Left+=e.X-x;
this.Top+=e.Y-y;
}
private void splitter1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
press2=true;
x2=e.X;y2=e.Y;
}
private void splitter1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
{
press2=false;
}
private void splitter1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
if(press2)
{
this.Width+=e.X-x2;
this.Height+=e.Y-y2;
}
}
}
}