本文整理汇总了C#中System.Windows.Forms.RichTextBox.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.BeginInvoke方法的具体用法?C# RichTextBox.BeginInvoke怎么用?C# RichTextBox.BeginInvoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.BeginInvoke方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: dodajWiadomosc
public void dodajWiadomosc(RichTextBox rt, string w)
{
if (rt.InvokeRequired)
rt.BeginInvoke(new Action<RichTextBox, string>(dodajWiadomosc), rt, w);
else
rt.AppendText(w + Environment.NewLine);
}
示例2: AppendMsg
/// <summary>
/// 在富文本上打印消息
/// </summary>
/// <param name="richTextBox1">所在打印的富文本</param>
/// <param name="color">打印字体颜色</param>
/// <param name="text">要打印的文本</param>
/// <param name="AutoTime">是否在每条打印结果前追加时间</param>
public void AppendMsg(RichTextBox richTextBox1, Color color, string text,bool AutoTime)
{
richTextBox1.BeginInvoke(new ThreadStart(() =>
{
lock (richTextBox1)
{
//为控件输入焦点
richTextBox1.Focus();
//检查文本框过长
if (richTextBox1.TextLength > 100000 )
{
richTextBox1.Clear();
}
//得到有格式的文本
using (var temp = new RichTextBox())
{
temp.SelectionColor = color;
if (AutoTime)
temp.AppendText(DateTime.Now.ToString("yyyyMMdd HH:mm:ss"));
temp.AppendText(text);
//追加文本
richTextBox1.Select(richTextBox1.Rtf.Length, 0);
richTextBox1.SelectedRtf = temp.Rtf;
}
//设定光标所在位置
//richTextBox1.SelectionStart = richTextBox1.TextLength;
//滚动到当前光标处
//richTextBox1.ScrollToCaret();
}
}));
}
示例3: RichTextAddMessage
public static void RichTextAddMessage(RichTextBox richText, string message, Color color, FontStyle? font)
{
if (richText.InvokeRequired)
{
var cb = new RichTextAddMessageCallback(RichTextAddMessageInternal);
richText.BeginInvoke(cb, message, color);
}
else
{
RichTextAddMessageInternal(richText, message, color, font);
}
}
示例4: 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();
}
}
}
}
示例5: AppendToRichEditControl
/// <summary>
/// Method to append text on a RichTextBox
/// </summary>
/// <param name="msg">String type message</param>
/// <param name="richTextBox">Richtextbox to append text</param>
private void AppendToRichEditControl(string msg, RichTextBox richTextBox)
{
// Check to see if this method is called from a thread
// other than the one created the control
if (richTextBox.InvokeRequired)
{
// We cannot update the GUI on this thread.
// All GUI controls are to be updated by the main (GUI) thread.
// Hence we will use the invoke method on the control which will
// be called when the Main thread is free
// Do UI update on UI thread
object[] pList = { msg + Environment.NewLine, richTextBox };
richTextBox.BeginInvoke(new UpdateRichEditCallback(AppendToRichEditControl), pList);
}
else
{
// This is the main thread which created this control, hence update it
// directly
richTextBox.AppendText(msg);
}
}
示例6: LogTextEvent
public void LogTextEvent(RichTextBox TextEventLog, string EventText,Color TextColor)
{
if (TextEventLog.InvokeRequired)
{
TextEventLog.BeginInvoke(new Action(delegate
{
LogTextEvent(TextEventLog, EventText, TextColor );
}));
return;
}
string nDateTime = DateTime.Now.ToString("[hh:mm:ss tt]") + " - ";
// color text.
TextEventLog.SelectionStart = TextEventLog.Text.Length;
TextEventLog.SelectionColor = TextColor;
// newline if first line, append if else.
if (TextEventLog.Lines.Length == 0)
{
TextEventLog.AppendText(nDateTime + EventText);
TextEventLog.ScrollToCaret();
TextEventLog.AppendText(System.Environment.NewLine);
}
else
{
TextEventLog.AppendText(nDateTime + EventText + System.Environment.NewLine);
TextEventLog.ScrollToCaret();
}
}
示例7: AddToRTB
public static void AddToRTB(RichTextBox rtb,string strText, Color textColor, float fontSize, bool bold, enumIcon icon)
{
if(rtb.InvokeRequired)
{
rtb.BeginInvoke(new delA(AddToRTB), new object[] { rtb, strText, textColor, fontSize, bold, icon });
return;
}
FontStyle style1 = bold ? FontStyle.Bold : FontStyle.Regular;
if (fontSize <= 0)
fontSize = 8;
Font font1 = new Font("Courier New", fontSize, style1, GraphicsUnit.Point, 0);
rtb.SelectionStart = rtb.TextLength;
rtb.SelectionFont = font1;
rtb.SelectionColor = textColor;
rtb.SelectedText = strText;
addIconToRtb(rtb,icon);
}
示例8: AppendText
/// <summary>
/// Append text of the given color.
/// </summary>
/// <param name="box"></param>
/// <param name="color"></param>
/// <param name="text"></param>
void AppendText(RichTextBox box, Color color, string text)
{
Application.DoEvents();
box.BeginInvoke((MethodInvoker)delegate
{
int start = box.TextLength;
box.AppendText(text);
int end = box.TextLength;
// Textbox may transform chars, so (end-start) != text.Length
box.Select(start, end - start);
{
box.SelectionColor = color;
// could set box.SelectionBackColor, box.SelectionFont too.
}
box.SelectionLength = 0; // clear
box.ScrollToCaret();
});
}
示例9: ClearRtbSafely
public static void ClearRtbSafely(RichTextBox rtb)
{
if (rtb.InvokeRequired)
{
rtb.BeginInvoke(new del1(ClearRtbSafely), new object[] { rtb });
return;
}
rtb.Clear();
}