页面代码【由于实现了代码封装,所有页面代码较少】
using DemoRichText.Model;
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 DemoRichText
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
public void btnButtonClick(object sender, EventArgs e) {
Button btn = (Button)sender;
BTNType btnType;
if (Enum.TryParse<BTNType>(btn.Tag.ToString(), out btnType)) {
if (btnType == BTNType.Search) {
if (!string.IsNullOrEmpty(this.txtSearch.Text.Trim()))
{
this.rtbInfo.Tag = this.txtSearch.Text.Trim();
}
else {
return;
}
}
IRichFormat richFomat = RichFormatFactory.CreateRichFormat(btnType);
richFomat.SetFormat(this.rtbInfo);
}
}
private void combFontSize_SelectedIndexChanged(object sender, EventArgs e)
{
float fsize = 12.0f;
if (combFontSize.SelectedIndex > -1) {
if (float.TryParse(combFontSize.SelectedItem.ToString(), out fsize)) {
rtbInfo.Tag = fsize.ToString();
IRichFormat richFomat = RichFormatFactory.CreateRichFormat(BTNType.FontSize);
richFomat.SetFormat(this.rtbInfo);
}
return;
}
}
}
}
RichTextBox是一个功能丰富的控件,值得学习。
点击文末原文地址下载源码。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。
注:相关教程知识阅读请移步到c#教程频道。










