在C#.net中使用控件richtextbox如何实现自动文字滚动

使用richtextbox,使文字向上滚动.就像电子书滚动一样.希望效果能实现平滑滚动,不要闪屏最好,当然,用timer控制可以,我希望能用API实现,并附详细的API参数说明.

使用了两个Lable1、两个textBox、一个Button、一个timer控件
private System.Windows.Forms.Button btnStringRoll;
private System.Windows.Forms.TextBox tbTextRoll;
private System.Windows.Forms.TextBox tbTextAutoRoll;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;

Form1.cs:代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 代码练习1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
/// <summary>
/// tbTextRoll.Text 显示 点击一次按钮,滚动一个字符
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnStringRoll_Click(object sender, EventArgs e)
{
string str = tbTextRoll.Text;
char first = str[0];
string surplus = str.Substring(1); //取出剩余的字符
tbTextRoll.Text = surplus + first;
}
/// <summary>
/// tbTextAutoRoll.Text 运行就 自动 滚动一个字符
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void timer1_Tick(object sender, EventArgs e)
{
string str = tbTextAutoRoll.Text;
char first = str[0];
string surplus = str.Substring(1); //取出剩余的字符
tbTextAutoRoll.Text = surplus + first;
}

private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Start();
timer1.Interval = 300; //事件间隔时间
}
}
}

Form1.Designer.cs
namespace 代码练习1
{
partial class Form1
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows 窗体设计器生成的代码

/// <summary>
/// 设计器支持所需的方法 - 不要
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.btnStringRoll = new System.Windows.Forms.Button();
this.tbTextRoll = new System.Windows.Forms.TextBox();
this.tbTextAutoRoll = new System.Windows.Forms.TextBox();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// btnStringRoll
//
this.btnStringRoll.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnStringRoll.Location = new System.Drawing.Point(12, 44);
this.btnStringRoll.Name = "btnStringRoll";
this.btnStringRoll.Size = new System.Drawing.Size(90, 41);
this.btnStringRoll.TabIndex = 0;
this.btnStringRoll.Text = "点击一次\r\n滚动一次 ";
this.btnStringRoll.UseVisualStyleBackColor = true;
this.btnStringRoll.Click += new System.EventHandler(this.btnStringRoll_Click);
//
// tbTextRoll
//
this.tbTextRoll.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.tbTextRoll.Location = new System.Drawing.Point(108, 53);
this.tbTextRoll.Multiline = true;
this.tbTextRoll.Name = "tbTextRoll";
this.tbTextRoll.Size = new System.Drawing.Size(293, 27);
this.tbTextRoll.TabIndex = 1;
this.tbTextRoll.Text = "这是滚动的字符!滚动方向是自右向左!";
//
// tbTextAutoRoll
//
this.tbTextAutoRoll.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.tbTextAutoRoll.Location = new System.Drawing.Point(86, 166);
this.tbTextAutoRoll.Multiline = true;
this.tbTextAutoRoll.Name = "tbTextAutoRoll";
this.tbTextAutoRoll.Size = new System.Drawing.Size(296, 28);
this.tbTextAutoRoll.TabIndex = 3;
this.tbTextAutoRoll.Text = "这是滚动的字符!滚动方向是自右向左!";
//
// timer1
//
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label1.Location = new System.Drawing.Point(129, 143);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(199, 20);
this.label1.TabIndex = 4;
this.label1.Text = "tbTextAutoRoll.Text";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.label2.Location = new System.Drawing.Point(142, 30);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(159, 20);
this.label2.TabIndex = 5;
this.label2.Text = "tbTextRoll.Text";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(413, 269);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.tbTextAutoRoll);
this.Controls.Add(this.tbTextRoll);
this.Controls.Add(this.btnStringRoll);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Button btnStringRoll;
private System.Windows.Forms.TextBox tbTextRoll;
private System.Windows.Forms.TextBox tbTextAutoRoll;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
}
}
温馨提示:内容为网友见解,仅供参考
无其他回答