zoukankan
html css js c++ java
c#中WinForm的TextBox循环自动滚动示例
这个问题来自论坛提问,演示代码如下
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中让文字循环滚动:
///
作者jinjazz
///
作者blog:
http://blog.csdn.net/jinjazz
///
</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();
}
}
}
查看全文
相关阅读:
vb.net structure 定义静态数组
调色板原理 & 编程
CView::OnPreparePrinting
MFC单文档程序架构解析
基于Eclipse远程调试解决的预上线首页打开特别慢的问题
Shiro Filter引发的思考
Shiro Filter中利用Callable和Runnable的委派模式
Shiro DefaultFilter
防止Form表单重复提交的客户端及服务器端的方式
Shiro Filter的设计概念
原文地址:https://www.cnblogs.com/cl1024cl/p/6204942.html
最新文章
MySQL 5.7.9修改root密码以及新特性
MySQL多实例启动停止
linux /etc/security/limits.conf的相关说明
Linux查看进程运行的完整路径方法
统计TCP网络连接情况
linux下安装nmon监控工具
修改mysql的root密码
CPU卡
raid
一维码和二维码
热门文章
windows CE项目开发
C# 16进制与字符串、字节数组之间的转换
C#与C++数据类型比较及结构体转换[整理]
Servlet的异常处理机制
Jsp与servlet的区别
Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明
Sql Server 2005中的架构(Schema)、用户(User)、登录(Login)和角色(Role)(一)
Windows编程基础
VC++ 6.0 BUG BUG BUG BUG BUG
vb.net 调用api
Copyright © 2011-2022 走看看