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();
}
}
}
查看全文
相关阅读:
Java实现批量下载《神秘的程序员》漫画
mysql远程连接:ERROR 1130 (HY000): Host '*.*.*.*' is not allowed to connect to this MySQL server解决办法
opencv学习_15 (利用cmake查看opencv的源码)
jobs 命令
中断子系统6_中断嵌套处理
JPA一对多映射
JPA Map映射
JPA集合映射
JPA删除实体
JPA查找实体
原文地址:https://www.cnblogs.com/cl1024cl/p/6204942.html
最新文章
[Python] Putting Code on PyPi
[CSS] Resest CSS
[Python] Making a package
[Functional Programming] Alternative operator for Either
访问win10的远程桌面(Remote Desktop)总是凭据或者用户密码错误
Android的Databinding-需要使用控件id,listener以及布局有include的场景
Android的Databinding-自定义生成类名字
Android的Databinding-普通绑定
c#之第四课
c#之第三课
热门文章
c#之第二课
c#之第一课入门
python之对指定目录文件夹的批量重命名
ios之VFL的补充(三)
ios之VFL的补充(二)
CityEngine中动态水的实现
unity --项目总结
MyEclipse取消验证Js的两种途径.
Oracle DB 存储增强
NSLog函数重写
Copyright © 2011-2022 走看看