winfrom中可以让listbox中得数据 自动循环滚动吗?

tangserver 2009-04-22 09:56:06
我现在有个listbox,行数是固定得,就想要它像某些网站上一样循环滚动,要是能做到鼠标放上去就停下最好了
...全文
197 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangserver 2009-04-22
  • 打赏
  • 举报
回复
是winfrom程序,如果用TextBox怎么把DataSet里面得数据给TextBox显示呢?
freewind0521 2009-04-22
  • 打赏
  • 举报
回复
给个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中让文字循环滚动:
/// </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();
}
}
}
cpio 2009-04-22
  • 打赏
  • 举报
回复
你是想要滚动条也滚动还是说内容滚动?

如果只是内容滚动,不用ListBox也可以,用TextBox就行

用一个Timer,在Timer里面把内容顺序改变一下

用一个变量记录当前最上面一条数据是第几条
ztenv 2009-04-22
  • 打赏
  • 举报
回复
winform中可以用timer来控件,但效果不好,会一行一行的跳动,
阿非 2009-04-22
  • 打赏
  • 举报
回复
asp.net?
glpizi 2009-04-22
  • 打赏
  • 举报
回复
javascript就有這種效果,csdn有的下!
LoveLife_Go 2009-04-22
  • 打赏
  • 举报
回复
学习
CeShenBeiWang 2009-04-22
  • 打赏
  • 举报
回复
脚本 不好意思 呵呵
CeShenBeiWang 2009-04-22
  • 打赏
  • 举报
回复
用脚步可以实现吧
tangserver 2009-04-22
  • 打赏
  • 举报
回复
自己解决了,谢谢大家
listBox1.SelectedItem = listBox1.Items[listBox1.SelectedIndex + 1];
就可以了

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧