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();
}
}
}
查看全文
相关阅读:
(转)Scrapy 深入一点点
解决Scrapy shell启动出现UnicodeEncodeError问题
js回调方法
UGUI 之 控件以及按钮的监听事件系统 存档
重力感应示例
网格概念
Flash Player11异步解码Bitmap
打包包含已修改过的bug
ios7官方推荐icon尺寸
项目资源通过swc获取
原文地址:https://www.cnblogs.com/cl1024cl/p/6204942.html
最新文章
关于 ARM Cortex-M3 的启动文件分析及分散加载
Nordic SDK nrf_setion和nrf_section_iter模块分析
CSR867x 编译错误:找不到头文件 gatt_manager_data.h
2、奉加微 PHY6202 OTA
评判是人工智能性能的准则
很多人问android好还是QT好?
安装交叉编译工具链gcc-3.4.5-glibc-2.3.6.tar.bz2后,遇到问题
解决从源码编译ncurses6.0编译lib_gen.c报错的问题
.NET Framework v4.0安装失败 (win7下)
win7下的cuteftp无法连接ubuntu虚拟机
热门文章
linux下安装为知笔记&apt-get update出现问题
RS485和RS232区别
使用图灵机器人api开发个人智能机器人
Tornado 编写安全应用
Python数据库连接池模块-----DBUtils使用
python多线程编程之Queue---put/get 方法的阻塞
Python时间,日期,时间戳之间转换
转 Django url 标签的使用
python中的yield
抓取scrapy中文文档 第一个Scrapy项目实现
Copyright © 2011-2022 走看看