本文整理汇总了C#中System.Windows.Forms.RichTextBox.ScrollToCaret方法的典型用法代码示例。如果您正苦于以下问题:C# RichTextBox.ScrollToCaret方法的具体用法?C# RichTextBox.ScrollToCaret怎么用?C# RichTextBox.ScrollToCaret使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.RichTextBox
的用法示例。
在下文中一共展示了RichTextBox.ScrollToCaret方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: wyswietl
public void wyswietl(RichTextBox o, string tekst)
{
o.Focus();
o.AppendText(tekst);
o.ScrollToCaret();
txtWysylane.Focus();
}
示例3: AppendText
private void AppendText(RichTextBox box, string text)
{
Invoke(new MethodInvoker(() =>
{
box.AppendText(text + "\r\n");
box.ScrollToCaret();
}));
}
示例4: Append
void Append(RichTextBox rtb, string message)
{
rtb.AppendText(message);
if (rtb.TextLength > 2048) {
rtb.Text = rtb.Text.Substring(rtb.TextLength - 2048);
}
rtb.SelectionStart = rtb.TextLength;
rtb.ScrollToCaret();
}
示例5: UyariGoster
public void UyariGoster(string msj, RichTextBox txtMesajlar)
{
if (txtMesajlar.Text != "")
{
txtMesajlar.AppendText("\r\n");
}
Yazdir("Bilgi: " + msj, adtarihFontColor, adtarihFont, adtarihKertmeDegeri, "", txtMesajlar);
txtMesajlar.ScrollToCaret();
}
示例6: AppendText
public static void AppendText(RichTextBox box, string text, Color color)
{
box.SelectionStart = box.TextLength;
box.SelectionLength = 0;
box.SelectionColor = color;
box.AppendText(text);
box.SelectionColor = box.ForeColor;
box.SelectionStart = box.TextLength;
box.ScrollToCaret();
box.Refresh();
}
示例7: appendMsg
public void appendMsg(RichTextBox t, string text)
{
if (this.InvokeRequired)
{
this.Invoke(new Action<RichTextBox, string>(appendMsg), new object[] { t, text });
}
else
{
t.AppendText(text);
t.ScrollToCaret();
}
}
示例8: 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();
}));
}
}
}
示例9: 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();
}
}
示例10: AddMessage
/// <summary>
/// Пишет сообщение в RichBox и в файл лога.
/// </summary>
/// <param name="logBox"></param>
/// <param name="message"></param>
/// <param name="logType">0-info;1-ошибка</param>
static void AddMessage(RichTextBox logBox, string message, int logType)
{
logBox.AppendText($"\n{message}\n");
logBox.Refresh();
logBox.ScrollToCaret();
if (logType == 0)
{
log.Info(message);
}
else
{
log.Error(message);
}
}
示例11: MesajGoster
public void MesajGoster(string msj, string ad, RichTextBox txtMesajlar)
{
StringBuilder sbAdTarih = new StringBuilder();
if (txtMesajlar.Text != "") // Ýlk mesaj geldiðinde bir alt satýra(caret için) geçilmesin, diðer mesajlarda geçilsin...
{
txtMesajlar.AppendText("\r\n");
}
sbAdTarih.Append(ad).Append(" [").Append(DateTime.Now.ToShortTimeString()).Append("] : ");
Yazdir(sbAdTarih.ToString(), adtarihFontColor, adtarihFont, adtarihKertmeDegeri, "\r\n", txtMesajlar);
Yazdir(msj, yazilarFontColor, yazilarFont, yazilarKertmeDegeri, "",txtMesajlar);
txtMesajlar.ScrollToCaret(); // Scroolbar aþaðý insin. caret = cursor
}
示例12: SetText
private void SetText(RichTextBox tb, string text)
{
// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
if (tb.InvokeRequired)
{
SetTextCallback d = new SetTextCallback(SetText);
this.BeginInvoke(d, new object[] { tb, text });
}
else
{
tb.AppendText(text);
tb.ScrollToCaret();
}
}
示例13: 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();
}
}
}
示例14: 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();
}
}
}
}
示例15: exec_Sql
public DataTable exec_Sql(string sql, NpgsqlConnection conn,RichTextBox t)
{
DataTable dt = new DataTable();
try
{
NpgsqlCommand cmd = new NpgsqlCommand(sql, conn);
NpgsqlDataReader r;
r = cmd.ExecuteReader();
if (r.HasRows)
{
dt.Load(r);
r.Close();
}
r.Close();
int length = t.TextLength;
string msg = "Succesfull Query!";
t.AppendText(DateTime.Now + " "+msg + "\n");
t.SelectionStart = length;
int flength = msg.Length + DateTime.Now.ToString().Length + 1;
t.SelectionLength = flength;
t.SelectionColor = Color.Green;
t.ScrollToCaret();
}
catch (Exception ex)
{
int length = t.TextLength;
t.AppendText(DateTime.Now + " " + ex.Message + "\n");
t.SelectionStart = length;
int flength = ex.Message.Length + DateTime.Now.ToString().Length + 1;
t.SelectionLength = flength;
t.SelectionColor = Color.Red;
t.ScrollToCaret();
}
return dt;
}