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();
}
}
}
查看全文
相关阅读:
杰我教育-新老学员交流会
来杰我学IT,好就业
怎么创建maven项目
项目开发生命周期
2015年12月28日,我工作了
SSH架构图及各部分知识点
jsp基础大全
网站创建过程(二)
网站创建过程(一)
python+Django+mysql环境搭建
原文地址:https://www.cnblogs.com/cl1024cl/p/6204942.html
最新文章
web初学之重定向与请求转发
web初学之jdbc连接数据库
win8.1无法安装安装.net framework 3.5 解决办法【转】
怎么在VS2010中打开VS2013的项目
如何在ashx页面获取Session值
Merge的山寨版“联机帮助”
SQL CTE 递归分割以逗号分隔的字符串
UBUNTU php 编译安装
YIi 设置 ajax 验证
Yii model rules使用
热门文章
YIi sql 输出
YII 缓存的一些问题
YIi 数据操作备注
Yii 设置简写或者全局函数
Yii 设置默认值
JQzoom的一些问题
APACHE 重写的一些 转载 供自己使用
技术改变生活
杰我科技新老学员交流会圆满成功
给自己一个机会,让我们帮你实现梦想
Copyright © 2011-2022 走看看