我们在C# TextBox操作的时候实现C# TextBox滚动的具体操作是什么呢?在C# TextBox使用的时候需要注意什么呢?那么本文就向你介绍这些具体内容。
C# TextBox翻滚完成详细的内容是什么?运用C# TextBox时需求留意什么呢?作为咱们编程的完成C# TextBox翻滚的操作细节是什么呢?那么下面咱们来看看详细的C# TextBox翻滚的操作完成以及C# TextBox运用需求留意的问题。
C# TextBox翻滚实例代码:
- usingSystem;
- usingSystem.Collections.Generic;
- usingSystem.ComponentModel;
- usingSystem.Data;
- usingSystem.Drawing;
- usingSystem.Text;
- usingSystem.Windows.Forms;
- usingSystem.Runtime.InteropServices;
- namespaceWindowsApplication27
- ...{
- /**////<summary>
- ///演示如安在TextBox中让文字循环翻滚:
- ///
- ///C#中WinForm的TextBox循环主动翻滚
- ///</summary>
- publicpartialclassForm1:Form
- ...{
- publicForm1()
- ...{
- InitializeComponent();
- this.textBox1.Clear();
- for(inti=0;i<=20;i++)
- ...{
- this.textBox1.Text+=string.Format("{0}:jinjazz__{1}",i,i);
- }
- this.timer1.Interval=200;
- this.timer1.Start();
- }
- //发送音讯
- [DllImport("user32.dll",EntryPoint="SendMessage")]
- publicstaticexternintSendMessage(
- IntPtrhWnd,intwMsg,intwParam,intlParam);
- //获取翻滚条方位
- [DllImport("user32")]
- publicstaticexternintGetScrollPos(IntPtrhwnd,intnBar);
- //设置翻滚条方位
- [DllImport("user32.dll")]
- staticexternintSetScrollPos(IntPtrhWnd,intnBar,
- intnPos,boolbRedraw);
- publicconstintEM_LINESCROLL=0xb6;
- privatevoidtimer1_Tick(objectsender,EventArgse)
- ...{
- inti=GetScrollPos(this.textBox1.Handle,1);
- //向下翻滚一行
- SendMessage(this.textBox1.Handle,
- EM_LINESCROLL,0,1);//0,1代表笔直翻滚条向下翻滚
- //判别是否有方位改变,假如没有则阐明到了底部,回来开端处
- if(i==GetScrollPos(this.textBox1.Handle,1))
- ...{
- //回到顶部,这儿用SetScrollPos好像有问题,翻滚条和文字不是同步更新
- this.textBox1.SelectionStart=0;
- this.textBox1.SelectionLength=1;
- this.textBox1.ScrollToCaret();
- this.textBox1.SelectionLength=0;
- }
- Console.WriteLine(i);
- }
- privatevoidtextBox1_MouseEnter(
- objectsender,EventArgse)
- ...{
- this.timer1.Stop();
- }
- privatevoidtextBox1_MouseLeave(
- objectsender,EventArgse)
- ...{
- this.timer1.Start();
- }
- }
- }
C# TextBox运用是要留意:
1、如安在多行TextBox中写入文本时完成换行:因为Windows体系中,回车符需两上字符。因而办法是运用\r\n符号,如
- Label="Calculation"+":.......SUM\r\n";
- textBox.AppendText(Label);
别的还有一个办法是用Environment.Newline的办法,能够兼容Windows和Linux体系。
2、如安在多行TextBox顶用翻滚条,使增加文本后主动翻滚显现到最后一行:办法是运用ScrollToCaret办法,主动翻滚到刺进符的方位,如:
- textBox.AppendText(Label);
- textBox.ScrollToCaret();
C# TextBox翻滚的完成以及C# TextBox运用时需求留意的基本内容就向你介绍到这儿,期望对你了解和学习C# TextBox翻滚、换行等等有所协助。
【修改引荐】
- C# CheckBox控件概念以及用处浅析
- 学习C# MessageBox用法的一点领会
- 浅析C# TextBox事情完成领会
- 浅析ASP.NET回车提交事情
- C# TextBox事情完成实例详解
转载请说明出处
知优网 » C# TextBox翻滚完成解析(c# textbox自动滚动)
知优网 » C# TextBox翻滚完成解析(c# textbox自动滚动)