WinFrom可视化编程给我们在编程的过程中带来了许多便利,本文将介绍怎么实现一个简单的编辑器。
话不多说直接上效果图和完整代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace 简历编辑器
{
public partial class btnColor : Form
{
string file = "jianli.rtf";
public btnColor()
{
InitializeComponent();
}
private void button3_Click(object sender, EventArgs e)
{
richTextBox1.Copy();
}
private void btnLoad_Click(object sender, EventArgs e)
{
richTextBox1.LoadFile(file);
}
private void btnSave_Click(object sender, EventArgs e)
{
richTextBox1.SaveFile(file);
}
private void btnCut_Click(object sender, EventArgs e)
{
richTextBox1 .Cut();
}
private void btnPaste_Click(object sender, EventArgs e)
{
richTextBox1.Paste();
}
private void btnBackColor_Click(object sender, EventArgs e)
{
richTextBox1.SelectionBackColor = Color.Blue;
}
private void button7_Click(object sender, EventArgs e)
{
richTextBox1.SelectionBackColor = Color.Green;
}
private void btnFont_Click(object sender, EventArgs e)
{
Font font = new Font("仿宋", 28);
richTextBox1.SelectionFont = font;
}
}
}
下面逐步讲解:
1)用VS创建一个窗体程序。
2)在工具箱中拖拽8个button 控件和一个richTextBox控件到窗体中根据自己的喜好对控件进行位置,大小调整,
3)设置控件的属性
窗体和控件 | 属性 | 属性值 |
From | Text | 简历编辑器 |
RichTextBox | Name | richTextBox1 |
button1 | Name Text | btnLoad 加载 |
button2 | Name Text | btnsave 保存 |
button3 | Name Text | btnCopy 复制 |
button4 | Name Text | btnCut 剪切 |
button5 | Name Text | btnPaste 粘贴 |
button6 | Name Text | btnBackColor 背景色 |
button7 | Name Text | btnColor 颜色 |
button8 | Name Text | btnFont 字体 |
RichTextBox控件与Text控件的作用相似,相当于Text的高配版。主要用于对RTF文件的操作。
4)双击每一个控件对控件要处理的事件进行添加。具体事件代码可以参照前面的完整代码。进行操作。
5)最后在生成的Debug文件下新建一个RTF文件。