WinForm中TextBox控件循环自动滚动示例
2009-08-17 10:54
351 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication27
...{
/**//// <summary>
/// 演示如何在TextBox中让文字循环滚动:
/// </summary>
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
this.textBox1.Clear();
for (int i = 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")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
//获取滚动条位置
[DllImport("user32")]
public static extern int GetScrollPos(IntPtr hwnd, int nBar);
//设置滚动条位置
[DllImport("user32.dll")]
static extern int SetScrollPos(IntPtr hWnd, int nBar,
int nPos, bool bRedraw);
public const int EM_LINESCROLL = 0xb6;
private void timer1_Tick(object sender, EventArgs e)
...{
int i= 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);
}
private void textBox1_MouseEnter(object sender, EventArgs e)
...{
this.timer1.Stop();
}
private void textBox1_MouseLeave(object sender, EventArgs e)
...{
this.timer1.Start();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsApplication27
...{
/**//// <summary>
/// 演示如何在TextBox中让文字循环滚动:
/// </summary>
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
this.textBox1.Clear();
for (int i = 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")]
public static extern int SendMessage(IntPtr hWnd, int wMsg, int wParam, int lParam);
//获取滚动条位置
[DllImport("user32")]
public static extern int GetScrollPos(IntPtr hwnd, int nBar);
//设置滚动条位置
[DllImport("user32.dll")]
static extern int SetScrollPos(IntPtr hWnd, int nBar,
int nPos, bool bRedraw);
public const int EM_LINESCROLL = 0xb6;
private void timer1_Tick(object sender, EventArgs e)
...{
int i= 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);
}
private void textBox1_MouseEnter(object sender, EventArgs e)
...{
this.timer1.Stop();
}
private void textBox1_MouseLeave(object sender, EventArgs e)
...{
this.timer1.Start();
}
}
}
相关文章推荐
- c#中WinForm的TextBox循环自动滚动示例
- c#中WinForm的TextBox循环自动滚动示例
- c#中WinForm的TextBox循环自动滚动示例
- c#中WinForm的TextBox循环自动滚动示例
- c#中WinForm的TextBox循环自动滚动示例
- (转)c#中WinForm的TextBox循环自动滚动
- LoopBanner 一个支持自动播放和循环滚动的banner控件
- winform中complete textbox,下拉自动完成控件
- WinForm中的TextBox控件输入全角数字自动转为半角数字
- OCUI界面设计:滚动视图与分页控件结合NSTimer实现图片自动循环与无限滚动展示
- Winform开发常用控件之DataGridView的简单数据绑定——自动绑定
- 编辑框控件:MFC编辑框自动换行,垂直滚动条自动下移
- 编辑框控件:MFC编辑框自动换行,垂直滚动条自动下移
- 禁止ScrollView在子控件的布局改变时自动滚动的的方法
- ScrollView嵌套ListView,GridView,ViewPager,以及这些控件自动滚动到底部问题的解决
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载续][重点推荐控件]
- Asp.net 2.0 自定义控件开发[实现自动计算功能(AutoComputeControl)][示例代码下载续][重点推荐控件]
- 图片自动滚动,循环播放Android auto-scroll-view-pager(转载)
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)
- Asp.net 2.0 自定义控件开发专题讲解[为用户控件增加DataSource属性, 能够自动识别不同数据源](示例代码下载)