old_flsystem/应用/Weixin.CircleTools/MethodExt.cs

35 lines
1002 B
C#
Raw Permalink Normal View History

2022-09-20 03:10:29 +00:00
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace CircleFriendsTools
{
public static class MethodExt
{
/// <summary>
/// 文本控件方法扩展
/// </summary>
/// <param name="rtBox"></param>
/// <param name="text">控件内容</param>
/// <param name="color">显示的颜色</param>
/// <param name="addNewLine">是否换行</param>
public static void AppendTextColorful(this RichTextBox rtBox, string text, Color color, bool addNewLine = true)
{
if (addNewLine)
{
text += Environment.NewLine;
}
rtBox.SelectionStart = rtBox.TextLength;
rtBox.SelectionLength = 0;
rtBox.SelectionColor = color;
rtBox.AppendText(text);
rtBox.SelectionColor = rtBox.ForeColor;
}
}
}