亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式

 更新時(shí)間:2023年03月01日 08:35:15   作者:楚楚3107  
這篇文章主要介紹了C#?WinForm?RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

WinForm RichTextBox文本動(dòng)態(tài)滾動(dòng)顯示文本方

在RichTextBox動(dòng)態(tài)顯示一些文本信息時(shí),需要一些設(shè)置,顯示當(dāng)前要顯示的字符串。

一個(gè)RichTextBox,一個(gè)按鈕。

下圖為運(yùn)行時(shí)顯示過(guò)程中

Form1.cs

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace RichTextBoxScroll
{
    public partial class Form1 : Form
    {
        private delegate void delInfoList(string text);
        public Form1()
        {
            InitializeComponent();
        }
        
        private void SetrichTextBox(string value)
        {
 
            if (richTextBox1.InvokeRequired)//其它線程調(diào)用
            {
                delInfoList d = new delInfoList(SetrichTextBox);
                richTextBox1.Invoke(d, value);
            }
            else//本線程調(diào)用
            {
                if (richTextBox1.Lines.Length > 100)
                { 
                    richTextBox1.Clear();
                }
 
                richTextBox1.Focus(); //讓文本框獲取焦點(diǎn) 
                richTextBox1.Select(richTextBox1.TextLength, 0);//設(shè)置光標(biāo)的位置到文本尾
                richTextBox1.ScrollToCaret();//滾動(dòng)到控件光標(biāo)處 
                richTextBox1.AppendText(value);//添加內(nèi)容
            }
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < 300; i++)
            {
                SetrichTextBox(DateTime.Now.ToString() + " 內(nèi)容滾動(dòng)打印中!!!\n");
            } 
        }
    }
}

Form1.Designer.cs

namespace RichTextBoxScroll
{
    partial class Form1
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;
 
 
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }
 
 
        #region Windows Form Designer generated code
 
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.button1 = new System.Windows.Forms.Button();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.panel1.SuspendLayout();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.Controls.Add(this.button1);
            this.panel1.Controls.Add(this.richTextBox1);
            this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.panel1.Location = new System.Drawing.Point(0, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(706, 496);
            this.panel1.TabIndex = 0;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(609, 85);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 1;
            this.button1.Text = "開(kāi)始測(cè)試";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // richTextBox1
            // 
            this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.richTextBox1.Font = new System.Drawing.Font("SimSun", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            this.richTextBox1.Location = new System.Drawing.Point(0, 0);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(706, 496);
            this.richTextBox1.TabIndex = 0;
            this.richTextBox1.Text = "";
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(706, 496);
            this.Controls.Add(this.panel1);
            this.Name = "Form1";
            this.Text = "滾動(dòng)打印測(cè)試";
            this.panel1.ResumeLayout(false);
            this.ResumeLayout(false);
 
 
        }
 
 
        #endregion
 
 
        private System.Windows.Forms.Panel panel1;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.Button button1;
    }
}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • C#實(shí)現(xiàn)在線更新軟件

    C#實(shí)現(xiàn)在線更新軟件

    winform程序相對(duì)web程序而言,功能更強(qiáng)大,編程更方便,但軟件更新卻相當(dāng)麻煩,要到客戶(hù)端一臺(tái)一臺(tái)地升級(jí),面對(duì)這個(gè)實(shí)際問(wèn)題,在最近的一個(gè)小項(xiàng)目中,本人設(shè)計(jì)了一個(gè)通過(guò)軟件實(shí)現(xiàn)自動(dòng)升級(jí)技術(shù)方案,彌補(bǔ)了這一缺陷,有較好的參考價(jià)值
    2015-05-05
  • C# 常用公共方法

    C# 常用公共方法

    這篇文章主要為大家詳細(xì)介紹了C# 常用公共方法,分享給大家,供大家參考,感興趣的小伙伴們可以參考一下
    2016-07-07
  • C#實(shí)現(xiàn)簡(jiǎn)易畫(huà)圖板的示例代碼

    C#實(shí)現(xiàn)簡(jiǎn)易畫(huà)圖板的示例代碼

    這篇文章主要介紹了C#實(shí)現(xiàn)簡(jiǎn)易畫(huà)圖板的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • C#代碼實(shí)現(xiàn)短信驗(yàn)證碼接口示例

    C#代碼實(shí)現(xiàn)短信驗(yàn)證碼接口示例

    這篇文章主要為大家詳細(xì)介紹了C#實(shí)現(xiàn)短信驗(yàn)證碼接口示例代碼,感興趣的小伙伴們可以參考一下
    2016-08-08
  • C#圖像處理之頭發(fā)檢測(cè)的方法

    C#圖像處理之頭發(fā)檢測(cè)的方法

    這篇文章主要介紹了C#圖像處理之頭發(fā)檢測(cè)的方法,可實(shí)現(xiàn)針對(duì)圖像中頭發(fā)的檢測(cè)功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2015-04-04
  • C#實(shí)現(xiàn)DVD借出歸還管理系統(tǒng)

    C#實(shí)現(xiàn)DVD借出歸還管理系統(tǒng)

    這篇文章主要介紹了C#實(shí)現(xiàn)DVD借出歸還管理系統(tǒng),類(lèi)似DVD管理器,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-06-06
  • C#設(shè)置程序開(kāi)機(jī)啟動(dòng)的實(shí)現(xiàn)示例

    C#設(shè)置程序開(kāi)機(jī)啟動(dòng)的實(shí)現(xiàn)示例

    本文主要介紹了C#設(shè)置程序開(kāi)機(jī)啟動(dòng)的實(shí)現(xiàn)示例,可以通過(guò)修改注冊(cè)表將啟動(dòng)信息寫(xiě)入注冊(cè)表來(lái)實(shí)現(xiàn),具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-01-01
  • C#實(shí)現(xiàn)帶行數(shù)和標(biāo)尺的RichTextBox

    C#實(shí)現(xiàn)帶行數(shù)和標(biāo)尺的RichTextBox

    這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)帶行數(shù)和標(biāo)尺的RichTextBox,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以跟隨小編一起了解一下
    2022-12-12
  • C#中4種深拷貝方法介紹

    C#中4種深拷貝方法介紹

    這篇文章主要介紹了C#中4種深拷貝方法介紹,本文講解了利用反射實(shí)現(xiàn)、利用xml序列化和反序列化實(shí)現(xiàn)、利用二進(jìn)制序列化和反序列化實(shí)現(xiàn)、利用silverlight DataContractSerializer實(shí)現(xiàn),用于在silverlight 客戶(hù)端使用等4種方法,需要的朋友可以參考下
    2015-06-06
  • C# 特性AttributeUsage簡(jiǎn)介與使用教程

    C# 特性AttributeUsage簡(jiǎn)介與使用教程

    這篇文章主要介紹了C# 特性AttributeUsage簡(jiǎn)介與使用教程,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05

最新評(píng)論