本文整理汇总了C#中System.Windows.Forms.RichTextBox.SuspendLayout方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.SuspendLayout方法的具体用法?C# RichTextBox.SuspendLayout怎么用?C# RichTextBox.SuspendLayout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.SuspendLayout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: setFontStyle
private void setFontStyle(RichTextBox rtb, FontStyle style)
{
if (rtb.SelectionLength == 0)
setCharFontStyle(rtb, style);
else
{
// to avoid screen refreshing, we create a fake RichTextBox
using (RichTextBox a = new RichTextBox())
{
a.SuspendLayout();
a.SelectedRtf = rtb.SelectedRtf;
a.SelectAll();
int selectionStart = a.SelectionStart;
int selectionLength = a.SelectionLength;
int selectionEnd = selectionStart + selectionLength;
for (int x = selectionStart; x < selectionEnd; ++x)
{
// Set temporary selection
a.Select(x, 1);
// Toggle font style of the selection
setCharFontStyle(a, style);
}
// Restore the original selection
a.SelectAll();
rtb.SelectedRtf = a.SelectedRtf;
}
}
}
示例2: AppendInternal
public static void AppendInternal(RichTextBox richTextBox, Color colorFore, Color colorBack, FontStyle newStyle, string text)
{
if(richTextBox != null && !string.IsNullOrEmpty(text) && !richTextBox.IsDisposed)
{
if(richTextBox.InvokeRequired)
{
richTextBox.BeginInvoke(new MethodInvoker(delegate() { AppendInternal(richTextBox, colorFore, colorBack, newStyle, text); }));
}
else
{
lock(richTextBox)
{
richTextBox.SuspendLayout();
//Truncate as necessary
if(richTextBox.Text.Length + text.Length > _maxConsoleTextLength)
{
int truncateLength = _maxConsoleTextLength / 4;
int endmarker = richTextBox.Text.IndexOf('\n', truncateLength) + 1;
if(endmarker < truncateLength)
endmarker = truncateLength;
richTextBox.Select(0, endmarker);
richTextBox.Cut();
}
int originalTextEnd = richTextBox.Text.Length;
richTextBox.AppendText(text);
richTextBox.Select(originalTextEnd, text.Length);
if(colorFore != Color.Empty)
richTextBox.SelectionColor = colorFore;
if(colorBack != Color.Empty)
richTextBox.SelectionBackColor = colorBack;
//if(newStyle != richTextBox.Font.Style)
richTextBox.SelectionFont = new Font(richTextBox.Font, newStyle);
richTextBox.SelectionLength = 0;
richTextBox.ScrollToCaret();
richTextBox.ResumeLayout();
richTextBox.Update();
}
}
}
}
示例3: AddTextToRTB
/// <summary>
/// Adds the text to RTB.
/// </summary>
/// <param name="richTextBox">The rich text box.</param>
/// <param name="stackCard">The stack card.</param>
/// <remarks>Documented by Dev08, 2009-05-12</remarks>
private void AddTextToRTB(RichTextBox richTextBox, StackCard stackCard)
{
richTextBox.SuspendLayout();
AnswerResult result = stackCard.Promoted ? AnswerResult.Correct : (stackCard.Result == AnswerResult.Almost ? AnswerResult.Almost : AnswerResult.Wrong);
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"<[^>]*>"); //to replace html code if any
bool questionRTL = stackCard.QuestionCulture.TextInfo.IsRightToLeft;
bool answerRTL = stackCard.AnswerCulture.TextInfo.IsRightToLeft;
richTextBox.BackColor = StackCardBackColors.ContainsKey(result) ? StackCardBackColors[result] : SystemColors.Window;
richTextBox.ForeColor = this.ForeColor;
string text = Environment.NewLine;
string questionRLE = (questionRTL ? Convert.ToString(Convert.ToChar(RLE)) : string.Empty);
text += questionRLE + regex.Replace(stackCard.Question, String.Empty) + Environment.NewLine;
text += questionRLE + regex.Replace(stackCard.QuestionExample, String.Empty) + Environment.NewLine;
text += Environment.NewLine;
string answerRLE = (answerRTL ? Convert.ToString(Convert.ToChar(RLE)) : string.Empty);
if (stackCard.LearnMode == MLifter.BusinessLayer.LearnModes.Sentence && stackCard.AnswerExample.Length > 0)
{
text += answerRLE + regex.Replace(stackCard.AnswerExample, String.Empty) + Environment.NewLine;
text += answerRLE + regex.Replace(stackCard.Answer, String.Empty) + Environment.NewLine;
}
else
{
text += answerRLE + regex.Replace(stackCard.Answer, String.Empty) + Environment.NewLine;
text += answerRLE + regex.Replace(stackCard.AnswerExample, String.Empty) + Environment.NewLine;
}
richTextBox.Visible = true;
richTextBox.Text = text;
richTextBox.Font = this.Font;
richTextBox.SelectAll();
richTextBox.SelectionFont = this.Font;
richTextBox.Select(0, 0);
richTextBox.ResumeLayout();
}
示例4: ParseLine
void ParseLine(string line, RichTextBox m_rtb, int startIndex = 0, int endIndex = 0)
{
if (line.Trim().Length < 1 && endIndex <= startIndex) return;
m_rtb.VScroll -= new EventHandler(newEditor_VScroll);
m_rtb.TextChanged -= new EventHandler(newEditor_TextChanged);
int startCursor = m_rtb.SelectionStart;
IntPtr eventMask = IntPtr.Zero;
Point ScrollPoint = GetScrollPos(m_rtb.Handle);
try
{
m_rtb.SuspendLayout();
// Stop redrawing:
SendMessage(m_rtb.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
// Stop sending of events:
eventMask = SendMessage(m_rtb.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
Regex r = new Regex("([ \\n\\t{}:;])");
int selectedIndex = startIndex;
int endingIndex = (endIndex > startIndex) ? endIndex : m_rtb.TextLength;
line = line.Substring(selectedIndex, endingIndex - selectedIndex);
String[] tokens = r.Split(line);
bool inProperty = false;
bool inDeclare = false;
bool inComment = false;
bool inValue = false;
int startComment = -1;
String token = "";
for (int tokenIndex = 0; tokenIndex < tokens.Count(); tokenIndex++)
{
token = tokens[tokenIndex];
if (token.Trim().Equals("")) {
selectedIndex += token.Length;
continue;
}
if (token.StartsWith("/*") || token.Contains("/*"))
{
startComment = selectedIndex;
inComment = true;
} else if (inComment && token.Contains("*/")) {
int closeComment = token.IndexOf("*/") + 1;
inComment = false;
int commentLength = (selectedIndex - startComment) + closeComment;
m_rtb.SelectionStart = startComment;
m_rtb.SelectionLength = commentLength;
m_rtb.SelectionColor = Color.Green;
token = token.Substring(closeComment);
selectedIndex += closeComment;
} else if (token.Equals(";") && !inComment)
{
inValue = false;
inProperty = false;
}
else if (token.Equals("{") && !inComment)
{
inDeclare = true;
}
else if (token.Equals("}") && !inComment)
{
inDeclare = false;
} else if (!inComment && token.Equals(":")) {
m_rtb.SelectionStart = selectedIndex;
m_rtb.SelectionLength = token.Length;
m_rtb.SelectionColor = Color.Black;
m_rtb.SelectedText = token;
inProperty = false;
inValue = true;
} else if (inValue && !inComment) {
if (token.StartsWith("#")) { //hex colors only
Regex hexColorCheck = new Regex(@"(^[#][A-Fa-f0-9]{3}$|^[#][A-Fa-f0-9]{6}$)");
if (hexColorCheck.IsMatch(token)) {
string colorToken = token;
if(token.Length == 4) { //a short 3 double color
colorToken = "#" + token[1] + token[1] + token[2] + token[2] + token[3] + token[3];
}
ColorConverter hexConvert = new ColorConverter();
Color hexColor = (Color) hexConvert.ConvertFromString(colorToken);
m_rtb.SelectionStart = selectedIndex;
m_rtb.SelectionLength = token.Length;
m_rtb.SelectionColor = hexColor;
m_rtb.SelectedText = token;
}
}
} else if (FormLanguage.tokenList.ContainsKey(token) && !inProperty && !inComment) {
SyntaxToken keyword = (SyntaxToken)FormLanguage.tokenList[token];
m_rtb.SelectionStart = selectedIndex;
m_rtb.SelectionLength = token.Length;
m_rtb.SelectionColor = keyword.Color;
m_rtb.SelectedText = token;
inProperty = true;
}
selectedIndex += token.Length;
//.........这里部分代码省略.........