原帖由 华丽的香蕉曲线 于 2008-7-2 19:46 发表
求方法+233MAX
话说真的要看
来了,其实也不复杂,核心部分就一点点,:
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 WindowsApplication1
{
public partial class Form1 : Form
{
public float oldValue;
public float vScrollMutiplier;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
FileStream fs;
try
{
saveFileDialog1.Filter = @"所有格式|*.txt;*.doc;|*.TXT|*.txt|*.DOC|*.doc";
saveFileDialog1.ShowDialog();
richTextBox1.SaveFile(saveFileDialog1.FileName.ToString(), RichTextBoxStreamType.PlainText);
}
catch { }
try
{
fs =File.Create(textBox1.Text);
}
catch {
return;
}
Byte[] content = new UTF8Encoding(true).GetBytes(richTextBox1.Text);
try {
fs.Write(content,0,content.Length);
fs.Flush();
MessageBox.Show("保存成功", "成功", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}catch{
MessageBox.Show("写入文件出错", "错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
}finally{
fs.Close();
}
}
///private void SetVerticalScrollMultipliter(Control ctrl) {
/// float hsb = (float)(vScrollBar1.Height-ctrl.Height);
/// float ticks = (float)(vScrollBar1.Maximum - vScrollBar1.Minimum);
/// vScrollMutiplier = hsb / ticks;
/// }
private void button3_Click(object sender, EventArgs e)
{
try
{
if (!File.Exists(textBox3.Text))
{
MessageBox.Show("文件不存在..");
}
FileStream fsa = File.OpenRead(textBox3.Text);
byte[] arr = new byte[1000];
UTF8Encoding data = new UTF8Encoding(true);
while (fsa.Read(arr, 0, arr.Length) > 0)
{
richTextBox1.Text = (data.GetString(arr));
}
}
catch (Exception ex) {
MessageBox.Show("出现错误"+ex.Message);
}
}
private void 复制ToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
}
catch { }
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void 版本ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 fud = new Form2();
fud.Show();
}
private void 保存ToolStripMenuItem1_Click(object sender, EventArgs e)
{
FileStream fs;
try
{
saveFileDialog1.Filter = @"所有格式|*.txt;*.doc;|*.TXT|*.txt|*.DOC|*.doc";
saveFileDialog1.ShowDialog();
richTextBox1.SaveFile(saveFileDialog1.FileName.ToString(), RichTextBoxStreamType.PlainText);
}
catch { }
try
{
fs = File.Create(textBox1.Text);
}
catch
{
return;
}
Byte[] content = new UTF8Encoding(true).GetBytes(richTextBox1.Text);
try
{
fs.Write(content, 0, content.Length);
fs.Flush();
MessageBox.Show("保存成功", "成功", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
}
catch
{
MessageBox.Show("写入文件出错", "错误", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
}
finally
{
fs.Close();
}
}
private void 字体ToolStripMenuItem_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
}
/// private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
/// {
/// float vAbsPos = (float)(vScrollBar1.Value - vScrollBar1.Minimum);
/// SetVerticalScrollMultipliter(pictureBox1);
/// if (vScrollBar1.Value > oldValue)
/// {
/// textBox2.Top = textBox2.Top - (int)(vScrollMutiplier * vAbsPos);
/// }
/// else if (vScrollBar1.Value < oldValue)
/// {
// / textBox2.Top = textBox2.Top + (int)(vScrollMutiplier * vAbsPos);
/// }
/// oldValue = vScrollBar1.Value;
/// }
}
}三杠线的是部分,待补全 |