日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
C#TextBox滾動(dòng)實(shí)現(xiàn)解析

C# TextBox滾動(dòng)實(shí)現(xiàn)具體的內(nèi)容是什么?使用C# TextBox時(shí)需要注意什么呢?作為我們編程的實(shí)現(xiàn)C# TextBox滾動(dòng)的操作細(xì)節(jié)是什么呢?那么下面我們來(lái)看看具體的C# TextBox滾動(dòng)的操作實(shí)現(xiàn)以及C# TextBox使用需要注意的問(wèn)題。

創(chuàng)新互聯(lián)專(zhuān)業(yè)為企業(yè)提供坡頭網(wǎng)站建設(shè)、坡頭做網(wǎng)站、坡頭網(wǎng)站設(shè)計(jì)、坡頭網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、坡頭企業(yè)網(wǎng)站模板建站服務(wù),十余年坡頭做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。

C# TextBox滾動(dòng)實(shí)例代碼:

 
 
 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Text;  
  7. using System.Windows.Forms;  
  8. using System.Runtime.InteropServices;  
  9. namespace WindowsApplication27  
  10. ...{  
  11. /**////   
  12. /// 演示如何在TextBox中讓文字循環(huán)滾動(dòng):  
  13. ///   
  14. /// C#中WinForm的TextBox循環(huán)自動(dòng)滾動(dòng)  
  15. ///   
  16. public partial class Form1 : Form  
  17. ...{  
  18. public Form1()  
  19. ...{  
  20. InitializeComponent();  
  21.  
  22. this.textBox1.Clear();  
  23. for (int i = 0; i <= 20;i++ )  
  24. ...{  
  25. this.textBox1.Text += string.Format("{0}:jinjazz__{1} ", i,i);  
  26. }  
  27. this.timer1.Interval = 200;  
  28. this.timer1.Start();  
  29. }  
  30.  
  31. //發(fā)送消息  
  32. [DllImport("user32.dll", EntryPoint = "SendMessage")]  
  33. public static extern int SendMessage(  
  34. IntPtr hWnd, int wMsg, int wParam, int lParam);  
  35. //獲取滾動(dòng)條位置  
  36. [DllImport("user32")]  
  37. public static extern int GetScrollPos(IntPtr hwnd, int nBar);  
  38. //設(shè)置滾動(dòng)條位置  
  39. [DllImport("user32.dll")]  
  40. static extern int SetScrollPos(IntPtr hWnd, int nBar,  
  41.    int nPos, bool bRedraw);  
  42.  
  43. public const int EM_LINESCROLL = 0xb6;  
  44.    
  45. private void timer1_Tick(object sender, EventArgs e)  
  46. ...{  
  47. int i=  GetScrollPos(this.textBox1.Handle,1);  
  48.  
  49. //向下滾動(dòng)一行  
  50. SendMessage(this.textBox1.Handle,   
  51. EM_LINESCROLL, 0, 1);//0,1代表垂直滾動(dòng)條向下滾動(dòng)  
  52.  
  53. //判斷是否有位置變化,如果沒(méi)有則說(shuō)明到了底部,返回開(kāi)始處  
  54. if (i == GetScrollPos(this.textBox1.Handle, 1))  
  55. ...{  
  56. //回到頂部,這里用SetScrollPos似乎有問(wèn)題,滾動(dòng)條和文字不是同步更新  
  57.  
  58. this.textBox1.SelectionStart = 0;  
  59. this.textBox1.SelectionLength = 1;  
  60. this.textBox1.ScrollToCaret();  
  61. this.textBox1.SelectionLength = 0;  
  62. }  
  63. Console.WriteLine(i);  
  64. }  
  65.  
  66. private void textBox1_MouseEnter(  
  67. object sender, EventArgs e)  
  68. ...{  
  69. this.timer1.Stop();  
  70. }  
  71.  
  72. private void textBox1_MouseLeave(  
  73. object sender, EventArgs e)  
  74. ...{  
  75. this.timer1.Start();  
  76. }  
  77. }  
  78. }  

C# TextBox使用是要注意:

1、如何在多行TextBox中寫(xiě)入文本時(shí)實(shí)現(xiàn)換行:由于Windows系統(tǒng)中,回車(chē)符需兩上字符。因此方法是使用\r\n標(biāo)記,如

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

另外還有一個(gè)辦法是用Environment.Newline的方法,可以兼容Windows和Linux系統(tǒng)。

2、如何在多行TextBox中用滾動(dòng)條,使添加文本后自動(dòng)滾動(dòng)顯示到最后一行:方法是使用ScrollToCaret方法,自動(dòng)滾動(dòng)到插入符的位置,如:

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

C# TextBox滾動(dòng)的實(shí)現(xiàn)以及C# TextBox使用時(shí)需要注意的基本內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C# TextBox滾動(dòng)、換行等等有所幫助。


文章標(biāo)題:C#TextBox滾動(dòng)實(shí)現(xiàn)解析
文章網(wǎng)址:http://m.5511xx.com/article/dhhppip.html