本文整理汇总了C#中System.Windows.Forms.TextBox.ScrollToCaret方法的典型用法代码示例。如果您正苦于以下问题:C# TextBox.ScrollToCaret方法的具体用法?C# TextBox.ScrollToCaret怎么用?C# TextBox.ScrollToCaret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.TextBox
的用法示例。
在下文中一共展示了TextBox.ScrollToCaret方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: add_text
public static void add_text(TextBox tb, object s)
{
if (tb.InvokeRequired)
tb.Invoke(new Action<TextBox, object>(add_text), new object[] { tb, s });
else
{
tb.AppendText(s.ToString());
tb.ScrollToCaret();
}
}
示例2: PositionTextDisplay
/// <summary>
/// Position the carat at the end of the text to keep the last bit into view
/// </summary>
public static void PositionTextDisplay(TextBox box)
{
int length = box.Text.Length;
if (Regex.IsMatch(box.Text, "(\r\n)$"))
{
length -= 2;
}
box.Select(length, 0);
box.ScrollToCaret();
}
示例3: PrintText
public void PrintText(TextBox textbox, string text)
{
if (textbox.InvokeRequired)
{
textbox.Invoke(new PrintTextCallback(PrintText), textbox, text);
}
else
{
textbox.Text += text;
textbox.SelectionStart = textbox.Text.Length;
textbox.ScrollToCaret();
}
}
示例4: PrintText
public void PrintText(string txt, TextBox printBox, Form owner)
{
if (printBox.InvokeRequired)
{
invokeTextBox d = new invokeTextBox(PrintText);
owner.Invoke(d, txt, printBox, owner);
}
else
{
printBox.Text += txt;
printBox.Select(printBox.Text.Length, 0);
printBox.ScrollToCaret();
}
}
示例5: DisplayData
public void DisplayData(string msg, TextBox listBox1)
{
listBox1.Invoke(new EventHandler(delegate
{
//listBox1.Font = new Font("Tahoma", 10, FontStyle.Regular);
//if (count > 720)
//{
// listBox1.Text = string.Empty;
// count = 0;
//}
listBox1.Text += msg + "\r\n";
listBox1.SelectionStart = listBox1.Text.Length;
listBox1.ScrollToCaret();
}));
}
示例6: appendLine
public void appendLine(string text,TextBox textBox)
{
BeginInvoke((Action)(() =>
{
if (textBox.Text.Length > 32000)
{
//新しいファイルに保存
textBox.Text = "";
}
textBox.AppendText(DateTime.Now.ToLongTimeString() + " " + text + Environment.NewLine);
textBox.SelectionStart = textBox.Text.Length;
textBox.ScrollToCaret();
}));
}
示例7: Atak
public void Atak(Postac atakujacy, Postac cel, TextBox komunikaty)
{
if(CzyTrafiono(atakujacy,cel))
{
Wykonaj(atakujacy,cel);
komunikaty.Text += string.Format("Atakujący {0} trafił {1}, użył umiejętności {2}\r\n",atakujacy.Nazwa,cel.Nazwa,Nazwa);
}
else
{
komunikaty.Text += string.Format("Atakujący {0} spudłował\r\n",atakujacy.Nazwa);
}
komunikaty.SelectionStart = komunikaty.Text.Length - 1;
komunikaty.SelectionLength = 0;
komunikaty.ScrollToCaret();
ZaplacZaUzycie(atakujacy);
}
示例8: AddLogEntry
public void AddLogEntry(string message,string thread)
{
if (!threadTabs.ContainsKey(thread))
{
TabPage tab = new TabPage();
tab.Location = new System.Drawing.Point(4, 22);
tab.Name = "tab" + thread.Trim().Replace(' ', '_');
tab.Padding = new System.Windows.Forms.Padding(3);
tab.Size = new System.Drawing.Size(859, 226);
tab.Text = thread;
tab.UseVisualStyleBackColor = true;
threadTabs[thread] = tab;
tabControl1.TabPages.Add(tab);
TextBox txtLogBox = new TextBox();
txtLogBox.Font = new System.Drawing.Font("Courier New", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
txtLogBox.Location = new System.Drawing.Point(6, 6);
txtLogBox.Multiline = true;
txtLogBox.Name = "txtLogBox";
txtLogBox.ScrollBars = System.Windows.Forms.ScrollBars.Both;
txtLogBox.Size = new System.Drawing.Size(847, 214);
txtLogBox.TabIndex = 1;
tab.Controls.Add(txtLogBox);
txtLogBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] - " + message + Environment.NewLine;
txtLogBox.SelectionStart = txtLogBox.Text.Length;
txtLogBox.ScrollToCaret();
txtLogBox.Refresh();
}
else
{
TabPage tab = threadTabs[thread];
TextBox txtLogBox = (TextBox) tab.Controls[0];
txtLogBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] - " + message + Environment.NewLine;
txtLogBox.SelectionStart = txtLogBox.Text.Length;
txtLogBox.ScrollToCaret();
txtLogBox.Refresh();
}
/*
txtLogBox.Text += "[" + DateTime.Now.ToLongTimeString() + "] - " + message + Environment.NewLine;
txtLogBox.SelectionStart = txtLogBox.Text.Length;
txtLogBox.ScrollToCaret();
txtLogBox.Refresh();
*/
}
示例9: LimitTextBox
/*
* limits input to integers and limits it to 0 to 100 values,
* rough way, but it works, it would take quite some time to change it to different way
* (like the ones on bottom that have two events for every textbox,
* both keypress and textchanged, maybe I'll change it eventually)
*
* `J` removed "LimitTextBoxRMax" and "LimitTextBoxRMin" variants that did the same thing
*/
private void LimitTextBox(TextBox tbox)
{
if (tbox.Text.Length > 0)
{
try
{
int test = int.Parse(tbox.Text);
}
catch
{
tbox.Text = tbox.Text.Substring(0, tbox.Text.Length - 1);
tbox.SelectionStart = tbox.Text.Length;
tbox.ScrollToCaret();
}
if (tbox.Text.Length < 1) { tbox.Text = "0"; } // `J` added this to prevent crash.
else if (int.Parse(tbox.Text) > 100) tbox.Text = "100";
}
}
示例10: AppendText
public static void AppendText(TextBox textBox, string text)
{
// If the current thread is not the UI thread, InvokeRequired will be true
if (textBox.InvokeRequired)
{
// If so, call Invoke, passing it a lambda expression which calls
// UpdateText with the same label and text, but on the UI thread instead.
textBox.Invoke((Action)(() => AppendText(textBox, text)));
return;
}
// If we're running on the UI thread, we'll get here, and can safely update
// the label's text.
textBox.AppendText(text);
textBox.ScrollToCaret();
}
示例11: MakeEndOfTextVisibleAndFocus
/// <summary>
/// Make sure that the end of the text in the given text box is visible.
/// An (undesired) side effect is to focus the box and put the selection at the end of it.
/// I cannot find any portable way to achieve the desired scrolling without doing this.
/// </summary>
/// <param name="textBox"></param>
private void MakeEndOfTextVisibleAndFocus(TextBox textBox)
{
if (textBox.Text.Length == 0)
return;
// It would seem logical that we would not want the -1, so we would be asking for the position of the
// imaginary character at the very end. However, that just always returns (0,0).
Point endPosition = textBox.GetPositionFromCharIndex(textBox.Text.Length - 1);
if (endPosition.X > textBox.Width)
{
textBox.Focus();
textBox.Select(textBox.Text.Length, 0);
textBox.ScrollToCaret();
}
}
示例12: ScrollToEnd
/// <summary>
/// Scrolls to end.
/// </summary>
/// <param name="tb">The tb.</param>
public static void ScrollToEnd(TextBox tb)
{
tb.SelectionStart = tb.TextLength;
tb.ScrollToCaret();
}
示例13: ScrollToBottom
private void ScrollToBottom(TextBox txtBox)
{
txtBox.SelectionStart = txtBox.Text.Length - 1;
txtBox.SelectionLength = 1;
txtBox.ScrollToCaret();
}
示例14: AddRecievedData
private void AddRecievedData(string data, TextBox textbox)
{
try
{
data = data.Replace("\n", "\r\n");
textbox.AppendText(data);
//textbox.Text += data;
textbox.SelectionStart = textbox.Text.Length;
textbox.ScrollToCaret();
}
catch (Exception ex)
{
Console.WriteLine("AddRecievedDataErroe:" + ex.Message);
}
}
示例15: SetLog
/// <summary>
/// Hiển thị Log lên textbox
/// </summary>
/// <param name="txt"></param>
/// <param name="text"></param>
private void SetLog(TextBox txt, object text)
{
if (txt != null && text != null)
{
Invoke((MethodInvoker)delegate
{
txt.Text += text + Environment.NewLine;
txt.SelectionStart = txt.Text.Length;
txt.ScrollToCaret();
});
}
}