本文整理汇总了C#中System.Windows.Forms.RichTextBox.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.Invoke方法的具体用法?C# RichTextBox.Invoke怎么用?C# RichTextBox.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AppendText
private void AppendText(string text, RichTextBox rtb)
{
if(rtb.InvokeRequired)
{
rtb.Invoke(new AppendTextDelegate(AppendText), text, rtb);
}
else
{
rtb.AppendText(text + Environment.NewLine);
}
}
示例2: SetSelectionColor
public static void SetSelectionColor(RichTextBox control, System.Drawing.Color color)
{
if (control.InvokeRequired)
control.Invoke(new SetSelectionColorDelegate(SetSelectionColor), control, color);
else
control.SelectionColor = color;
}
示例3: AppendMessage
/// <summary>
/// Writes a message to the specified RichTextBox.
/// </summary>
/// <param name="textBox"></param>
/// <param name="message">The <see cref="string">message</see> to be written.</param>
/// <param name="col"></param>
private static void AppendMessage(RichTextBox textBox, string message, Color col)
{
try
{
if (!textBox.IsDisposed)
{
if (textBox.InvokeRequired)
{
textBox.Invoke(new Action<RichTextBox, string, Color>(AppendMessage), textBox, message, col);
return;
}
Color oldColor = textBox.SelectionColor;
textBox.SelectionColor = col;
textBox.AppendText(message);
textBox.SelectionColor = oldColor;
textBox.AppendText(Environment.NewLine);
textBox.ScrollToCaret();
}
}
catch (Exception ex)
{
Logging.WriteException(ex);
}
}
示例4: AddLine
private void AddLine(RichTextBox RTB, string line)
{
if (RTB.InvokeRequired)
RTB.Invoke(new Action(() => RTB.AppendText(line + Environment.NewLine)));
else
RTB.AppendText(line + Environment.NewLine);
}
示例5: AddText
private void AddText(RichTextBox RTB, string msg)
{
if (RTB.InvokeRequired)
RTB.Invoke(new Action(() => RTB.AppendText(msg)));
else
RTB.AppendText(msg);
}
示例6: UpdateRtfText
public static void UpdateRtfText(RichTextBox i_RichTextBox, string i_Text)
{
if (i_RichTextBox.InvokeRequired)
{
i_RichTextBox.Invoke(new Action<RichTextBox, string>(UpdateRtfText), i_RichTextBox, i_Text);
}
else
{
i_RichTextBox.Rtf = i_Text;
}
}
示例7: AppendText
private void AppendText(RichTextBox ctrl, string text)
{
if (ctrl.InvokeRequired)
{
AppendText_Callback call = new AppendText_Callback(AppendText);
ctrl.Invoke(call, ctrl, text);
}
else
{
ctrl.AppendText(text);
ctrl.ScrollToCaret();
}
}
示例8: push
protected void push(RichTextBox box, string message)
{
// box.InvokeRequired may does not check properly
try {
box.Text += message;
}
catch
{
box.Invoke((MethodInvoker)delegate {
box.Text += message;
});
}
}
示例9: SetText
public static void SetText(string text, RichTextBox tb)
{
if (tb.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
tb.Invoke(d, new object[] { text, tb });
}
else
{
tb.AppendText(text);
tb.AppendText("\r\n");
}
}
示例10: AddMessageToControlInvoke
private void AddMessageToControlInvoke(RichTextBox sender, String message)
{
if (sender.InvokeRequired)
{
sender.Invoke(addMessage, message);
}
else
{
if (!String.IsNullOrEmpty(message))
{
sender.Text += String.Format("[{0}]{1}\r\n", DateTime.Now.ToString("yyMMdd HH:mm:ss"), message);
sender.SelectionStart = richTextBoxReceiver.TextLength;
sender.ScrollToCaret();
}
}
}
示例11: OutMsg
/// <summary>
/// 委托方式输出信息
/// </summary>
/// <param name="rtb">文本框实例</param>
/// <param name="msg">要输出的信息</param>
/// <param name="color">信息的颜色</param>
public static void OutMsg(RichTextBox rtb, string msg, Color color)
{
try
{
rtb.Invoke(new EventHandler(delegate
{
rtb.SelectionStart = rtb.Text.Length;
rtb.SelectionColor = color;
rtb.AppendText(msg + "\r\n");
rtb.ScrollToCaret();
if (rtb.Text.Length > 4000)
{
rtb.Text = string.Empty;
}
}));
}
catch (Exception)
{
Application.Exit();
}
}
示例12: BuildFile
// Functions
public void BuildFile(RichTextBox buildbox, string filename, string directory)
{
try
{
Process proc = new Process();
proc.StartInfo.Arguments = filename + " -i=\"" + Directory.GetCurrentDirectory() + "\\includes\"";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.FileName = "pawncc.exe";
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.WorkingDirectory = directory;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
string error = proc.StandardError.ReadToEnd();
proc.WaitForExit();
buildbox.Invoke(new MethodInvoker(delegate { buildbox.Text = error + "\n" + output.Replace("\r\n\r\n", "\r\n"); }));
}
catch (Exception ex) { mainform.Invoke(new MethodInvoker(delegate { mainform.CaughtException(ex); })); }
}
示例13: Log
/// <summary>
/// Logger to be able to see the events and operations in the server
/// </summary>
/// <param name="control"></param>
/// <param name="message"></param>
public static void Log(RichTextBox control, string message)
{
string formatted = string.Format("\r\n[{0}] {1}", DateTime.Now.ToString("MM-dd-yy hh:mm:ss"), message);
/// Invoke the message to the controll
/// http://msdn.microsoft.com/en-us/library/system.windows.forms.methodinvoker.aspx
if (!control.IsDisposed)
{
if (!control.InvokeRequired)
{
control.AppendText(formatted);
control.ScrollToCaret();
}
else
{
control.Invoke(((MethodInvoker)delegate
{
control.AppendText(formatted);
control.ScrollToCaret();
}));
}
}
}
示例14: updateMessageList
public void updateMessageList(RichTextBox messageList, ludo_client.dto.Message newIncomingMessage)
{
if (messageList.InvokeRequired)
{
// We're on a thread other than the GUI thread
messageList.Invoke(new MethodInvoker(() => updateMessageList(messageList, newIncomingMessage)));
return;
}
String timeStampSecond = newIncomingMessage.TimeStamp.Second.ToString();
if (timeStampSecond.Length == 1)
{
timeStampSecond = "0" + timeStampSecond;
}
String timeStamp = "[" + newIncomingMessage.TimeStamp.ToShortTimeString() +
":" + timeStampSecond + "]";
String sender = newIncomingMessage.Sender.UserName;
String message = newIncomingMessage.Msg;
messageList.AppendText(timeStamp + " ", Color.Gray);
messageList.AppendText(sender + ": " , Color.Blue);
messageList.AppendText(message + "\n");
messageList.ScrollToCaret();
}
示例15: ConnectLogger
public Task ConnectLogger(RichTextBox box)
{
return Task.Factory.StartNew(() =>
{
while (!_source.Token.IsCancellationRequested)
{
string result;
var builder = new StringBuilder();
while (_log.TryDequeue(out result))
{
builder.AppendLine(result);
}
if (builder.Length > 0)
{
box.Invoke(new Action(() =>
{
box.AppendText(builder.ToString());
box.ScrollToCaret();
}));
}
_source.Token.WaitHandle.WaitOne(TimeSpan.FromMilliseconds(250));
}
}, _source.Token);
}