我们在C# TextBox操作的时候实现C# TextBox滚动的具体操作是什么呢?在C# TextBox使用的时候需要注意什么呢?那么本文就向你介绍这些具体内容。

C# TextBox翻滚完成详细的内容是什么?运用C# TextBox时需求留意什么呢?作为咱们编程的完成C# TextBox翻滚的操作细节是什么呢?那么下面咱们来看看详细的C# TextBox翻滚的操作完成以及C# TextBox运用需求留意的问题。

C# TextBox翻滚完成解析(c# textbox自动滚动)  TextBox滚动 TextBox 第1张

C# TextBox翻滚实例代码:

  1. usingSystem;
  2. usingSystem.Collections.Generic;
  3. usingSystem.ComponentModel;
  4. usingSystem.Data;
  5. usingSystem.Drawing;
  6. usingSystem.Text;
  7. usingSystem.Windows.Forms;
  8. usingSystem.Runtime.InteropServices;
  9. namespaceWindowsApplication27
  10. ...{
  11. /**////<summary>
  12. ///演示如安在TextBox中让文字循环翻滚:
  13. ///
  14. ///C#中WinForm的TextBox循环主动翻滚
  15. ///</summary>
  16. publicpartialclassForm1:Form
  17. ...{
  18. publicForm1()
  19. ...{
  20. InitializeComponent();
  21. this.textBox1.Clear();
  22. for(inti=0;i<=20;i++)
  23. ...{
  24. this.textBox1.Text+=string.Format("{0}:jinjazz__{1}",i,i);
  25. }
  26. this.timer1.Interval=200;
  27. this.timer1.Start();
  28. }
  29. //发送音讯
  30. [DllImport("user32.dll",EntryPoint="SendMessage")]
  31. publicstaticexternintSendMessage(
  32. IntPtrhWnd,intwMsg,intwParam,intlParam);
  33. //获取翻滚条方位
  34. [DllImport("user32")]
  35. publicstaticexternintGetScrollPos(IntPtrhwnd,intnBar);
  36. //设置翻滚条方位
  37. [DllImport("user32.dll")]
  38. staticexternintSetScrollPos(IntPtrhWnd,intnBar,
  39. intnPos,boolbRedraw);
  40. publicconstintEM_LINESCROLL=0xb6;
  41. privatevoidtimer1_Tick(objectsender,EventArgse)
  42. ...{
  43. inti=GetScrollPos(this.textBox1.Handle,1);
  44. //向下翻滚一行
  45. SendMessage(this.textBox1.Handle,
  46. EM_LINESCROLL,0,1);//0,1代表笔直翻滚条向下翻滚
  47. //判别是否有方位改变,假如没有则阐明到了底部,回来开端处
  48. if(i==GetScrollPos(this.textBox1.Handle,1))
  49. ...{
  50. //回到顶部,这儿用SetScrollPos好像有问题,翻滚条和文字不是同步更新
  51. this.textBox1.SelectionStart=0;
  52. this.textBox1.SelectionLength=1;
  53. this.textBox1.ScrollToCaret();
  54. this.textBox1.SelectionLength=0;
  55. }
  56. Console.WriteLine(i);
  57. }
  58. privatevoidtextBox1_MouseEnter(
  59. objectsender,EventArgse)
  60. ...{
  61. this.timer1.Stop();
  62. }
  63. privatevoidtextBox1_MouseLeave(
  64. objectsender,EventArgse)
  65. ...{
  66. this.timer1.Start();
  67. }
  68. }
  69. }

C# TextBox运用是要留意:

1、如安在多行TextBox中写入文本时完成换行:因为Windows体系中,回车符需两上字符。因而办法是运用\r\n符号,如

  1. Label="Calculation"+":.......SUM\r\n";
  2. textBox.AppendText(Label);

别的还有一个办法是用Environment.Newline的办法,能够兼容Windows和Linux体系。

2、如安在多行TextBox顶用翻滚条,使增加文本后主动翻滚显现到最后一行:办法是运用ScrollToCaret办法,主动翻滚到刺进符的方位,如:

  1. textBox.AppendText(Label);
  2. textBox.ScrollToCaret();

C# TextBox翻滚的完成以及C# TextBox运用时需求留意的基本内容就向你介绍到这儿,期望对你了解和学习C# TextBox翻滚、换行等等有所协助。

【修改引荐】

  1. C# CheckBox控件概念以及用处浅析
  2. 学习C# MessageBox用法的一点领会
  3. 浅析C# TextBox事情完成领会
  4. 浅析ASP.NET回车提交事情
  5. C# TextBox事情完成实例详解
转载请说明出处
知优网 » C# TextBox翻滚完成解析(c# textbox自动滚动)

发表评论

您需要后才能发表评论