本文整理汇总了C#中System.Windows.Forms.RichTextBox.GetCharFormat方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.GetCharFormat方法的具体用法?C# RichTextBox.GetCharFormat怎么用?C# RichTextBox.GetCharFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.GetCharFormat方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessTags
private static string ProcessTags(RichTextBox rtb, List<KeyValuePair<int, string>> colFormat, bool bParaFormat)
{
StringBuilder sbT = new StringBuilder();
ctformatStates bold = ctformatStates.nctNone;
ctformatStates bitalic = ctformatStates.nctNone;
ctformatStates bstrikeout = ctformatStates.nctNone;
ctformatStates bunderline = ctformatStates.nctNone;
ctformatStates super = ctformatStates.nctNone;
ctformatStates sub = ctformatStates.nctNone;
ctformatStates bacenter = ctformatStates.nctNone;
ctformatStates baleft = ctformatStates.nctNone;
ctformatStates baright = ctformatStates.nctNone;
ctformatStates bnumbering = ctformatStates.nctNone;
bool fontSet = false;
string strFont = "";
Int32 crFont = 0;
Color color = new Color();
int yHeight = 0;
int i = 0;
int pos = 0;
int k = rtb.TextLength;
char[] chtrim = { ' ', '\x0000' };
//--------------------------------
// this is an inefficient method to get text format
// but RichTextBox doesn't provide another method to
// get something like an array of charformat and paraformat
//--------------------------------
for (i = 0; i < k; i++)
{
// select one character
rtb.Select(i, 1);
string strChar = rtb.SelectedText;
// get format for this character
CHARFORMAT cf = rtb.GetCharFormat();
PARAFORMAT pf = rtb.GetParaFormat();
string strfname = cf.szFaceName;
strfname = strfname.Trim(chtrim);
// new font format ?
if ((strFont != strfname) || (crFont != cf.crTextColor) || (yHeight != cf.yHeight))
{
KeyValuePair<int, string> mfr;
if (strFont != "")
{
// close previous <font> tag
mfr = new KeyValuePair<int, string>(pos, "</font>");
colFormat.Add(mfr);
}
// save this for cache
strFont = strfname;
crFont = cf.crTextColor;
yHeight = cf.yHeight;
fontSet = strFont != "";
// font size should be translate to
// html size (Approximately)
int fsize = yHeight / (20 * 5);
// color object from COLORREF
color = GetColor(crFont);
// add <font> tag
string strcolor = string.Concat("#", (color.ToArgb() & 0x00FFFFFF).ToString("X6"));
mfr = new KeyValuePair<int, string>(pos, "<font face=\"" + strFont + "\" color=\"" + strcolor + "\" size=\"" + fsize + "\">");
colFormat.Add(mfr);
}
// are we in another line ?
if ((strChar == "\r") || (strChar == "\n"))
{
// yes?
// then, we need to reset paragraph format
// and character format
if (bParaFormat)
{
bnumbering = ctformatStates.nctNone;
baleft = ctformatStates.nctNone;
baright = ctformatStates.nctNone;
bacenter = ctformatStates.nctNone;
}
// close previous tags
// is italic? => close it
if (bitalic != ctformatStates.nctNone)
{
var mfr = new KeyValuePair<int, string>(pos, "</i>");
colFormat.Add(mfr);
bitalic = ctformatStates.nctNone;
}
//.........这里部分代码省略.........