最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#在窗體中設(shè)計滾動字幕的方法

 更新時間:2024年04月21日 10:24:21   作者:wenchm  
普通窗體中的文字位置都是固定的,但在一些窗體中需要讓文字動起來,如一些廣告性較強的界面中需要做一些滾動的字幕,所以本文給大家介紹了C#在窗體中設(shè)計滾動字幕的方法,需要的朋友可以參考下

1.涉及到的知識點

本實例主要是通過Timer組件控制Label控件的移動來實現(xiàn)的,而Label控件的移動主要是通過設(shè)置其與窗體左邊距的相對位置來實現(xiàn)的。

(1)Timer組件

Timer計時器可以按用戶定義的時間間隔來引發(fā)事件,引發(fā)的事件一般為周期性的,每隔若干秒或若干毫秒執(zhí)行一次,其Interval屬性用來獲取或設(shè)置在相對于上一次發(fā)生的Tick事件引發(fā)Tick事件之前的時間(以毫秒為單位)。Interval屬性的語法格式如下:

public int Interval {get;set;}
參數(shù)說明
屬性值:指定在相對于上一次發(fā)生的Tick事件引發(fā)Tick事件之前的毫秒數(shù),該值不能小于1。

Timer組件的Enabled屬性用來獲取或設(shè)置計時器是否正在運行。語法格式如下:

public virtual bool Enabled {get;set;}
參數(shù)說明
屬性值:如果計時器當(dāng)前處于啟用狀態(tài),則為true;否則為false。默認(rèn)為false。

(2)Label控件的Left屬性

該屬性用來獲取或設(shè)置控件左邊緣與其容器的工作區(qū)左邊緣之間的距離(以像素為單位)。語法格式如下:

[BrowsableAttribute(false)]
public int Left{get;set;}
參數(shù)說明
屬性值:表示控件左邊緣與其容器的工作區(qū)左邊緣之間的距離(以像素為單位)。

Left屬性的值等效于Label控件的Location屬性值的Point.X屬性。

(3)啟動和關(guān)閉Timer計時器

啟動Timer計時器時,可以將其Enabled屬性設(shè)置為true,或者調(diào)用其Start方法;

而關(guān)閉Timer計時器時,則需要將其Enabled屬性設(shè)置為false,或者調(diào)用其Stop方法。

2. 實例

本實例實現(xiàn)了一個具有滾動字幕效果的窗體,運行本實例,單擊“演示”按鈕,將看到窗口中的文字開始滾動;單擊“暫停”按鈕,可以使字幕停止?jié)L動。

(1)Resources.Designer.cs設(shè)計

//------------------------------------------------------------------------------
// <auto-generated>
//     此代碼由工具生成。
//     運行時版本:4.0.30319.42000
//
//     對此文件的更改可能會導(dǎo)致不正確的行為,并且如果
//     重新生成代碼,這些更改將會丟失。
// </auto-generated>
//------------------------------------------------------------------------------
 
namespace _188.Properties {
    using System;
    
    
    /// <summary>
    ///   一個強類型的資源類,用于查找本地化的字符串等。
    /// </summary>
    // 此類是由 StronglyTypedResourceBuilder
    // 類通過類似于 ResGen 或 Visual Studio 的工具自動生成的。
    // 若要添加或移除成員,請編輯 .ResX 文件,然后重新運行 ResGen
    // (以 /str 作為命令選項),或重新生成 VS 項目。
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources {
        
        private static global::System.Resources.ResourceManager resourceMan;
        
        private static global::System.Globalization.CultureInfo resourceCulture;
        
        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources() {
        }
        
        /// <summary>
        ///   返回此類使用的緩存的 ResourceManager 實例。
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager {
            get {
                if (object.ReferenceEquals(resourceMan, null)) {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("_188.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }
        
        /// <summary>
        ///   重寫當(dāng)前線程的 CurrentUICulture 屬性,對
        ///   使用此強類型資源類的所有資源查找執(zhí)行重寫。
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Globalization.CultureInfo Culture {
            get {
                return resourceCulture;
            }
            set {
                resourceCulture = value;
            }
        }
        
        /// <summary>
        ///   查找 System.Drawing.Bitmap 類型的本地化資源。
        /// </summary>
        internal static System.Drawing.Bitmap _05 {
            get {
                object obj = ResourceManager.GetObject("_05", resourceCulture);
                return ((System.Drawing.Bitmap)(obj));
            }
        }
    }
}

(2) Form1.Designer.cs設(shè)計

namespace _188
{
    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()
        {
            components = new System.ComponentModel.Container();
            button1 = new Button();
            button2 = new Button();
            button3 = new Button();
            timer1 = new System.Windows.Forms.Timer(components);
            label1 = new Label();
            SuspendLayout();
            // 
            // button1
            // 
            button1.Location = new Point(267, 73);
            button1.Name = "button1";
            button1.Size = new Size(75, 23);
            button1.TabIndex = 0;
            button1.Text = "演示";
            button1.UseVisualStyleBackColor = true;
            button1.Click += Button1_Click;
            // 
            // button2
            // 
            button2.Location = new Point(267, 102);
            button2.Name = "button2";
            button2.Size = new Size(75, 23);
            button2.TabIndex = 1;
            button2.Text = "停止";
            button2.UseVisualStyleBackColor = true;
            button2.Click += Button2_Click;
            // 
            // button3
            // 
            button3.Location = new Point(267, 131);
            button3.Name = "button3";
            button3.Size = new Size(75, 23);
            button3.TabIndex = 2;
            button3.Text = "關(guān)閉";
            button3.UseVisualStyleBackColor = true;
            button3.Click += Button3_Click;
            // 
            // timer1
            // 
            timer1.Tick += Timer1_Tick;
            // 
            // label1
            // 
            label1.AutoSize = true;
            label1.Font = new Font("Microsoft YaHei UI", 18F);
            label1.ForeColor = Color.Red;
            label1.Location = new Point(1, 221);
            label1.Name = "label1";
            label1.Size = new Size(470, 31);
            label1.TabIndex = 3;
            label1.Text = "好消息:本店讓利大酬賓,所有商品八折。";
            // 
            // Form1
            // 
            AutoScaleDimensions = new SizeF(7F, 17F);
            AutoScaleMode = AutoScaleMode.Font;
            BackgroundImage = Properties.Resources._05;
            BackgroundImageLayout = ImageLayout.Stretch;
            ClientSize = new Size(354, 267);
            Controls.Add(label1);
            Controls.Add(button3);
            Controls.Add(button2);
            Controls.Add(button1);
            Name = "Form1";
            StartPosition = FormStartPosition.CenterScreen;
            Text = "窗體中滾動字幕";
            ResumeLayout(false);
            PerformLayout();
        }
 
        #endregion
 
        private Button button1;
        private Button button2;
        private Button button3;
        private System.Windows.Forms.Timer timer1;
        private Label label1;
    }
}

(3)Form1.cs設(shè)計

namespace _188
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();  
        }
        /// <summary>
        /// 開始滾動
        /// </summary>
        private void Button1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }
        /// <summary>
        /// 停止?jié)L動
        /// </summary>
        private void Button2_Click(object sender, EventArgs e)
        {
            timer1.Enabled = false;
        }
        /// <summary>
        /// 關(guān)閉窗體
        /// </summary>
        private void Button3_Click(object sender, EventArgs e)
        {
            Close();
        }
        /// <summary>
        /// 用Timer來控制滾動速度
        /// </summary>
        private void Timer1_Tick(object sender, EventArgs e)
        {
            label1.Left -= 2;        //設(shè)置label1左邊緣與其容器的工作區(qū)左邊緣之間的距離
            if (label1.Right < 0)    //當(dāng)label1右邊緣與其容器的工作區(qū)左邊緣之間的距離小于0時
            {
                label1.Left = Width; //設(shè)置label1左邊緣與其容器的工作區(qū)左邊緣之間的距離為該窗體的寬度
            }
        }
    }
}

(4) 生成效果

以上就是C#在窗體中設(shè)計滾動字幕的方法的詳細(xì)內(nèi)容,更多關(guān)于C#窗體滾動字幕的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • C# 枚舉類型的聲明和使用

    C# 枚舉類型的聲明和使用

    如果一種變量只有幾種可能的值,可以定義為枚舉類型。所謂“枚舉類型”是將變量的值一一列舉出來,變量的值只能在列舉出來的值的范圍內(nèi)
    2021-07-07
  • C#多線程及同步示例簡析

    C#多線程及同步示例簡析

    這篇文章主要為大家詳細(xì)介紹了C#多線程及同步示例,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • C# 枚舉的使用簡介

    C# 枚舉的使用簡介

    這篇文章主要介紹了C# 枚舉的簡單使用,幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下
    2021-03-03
  • C# 實現(xiàn)截圖軟件功能實例代碼

    C# 實現(xiàn)截圖軟件功能實例代碼

    這篇文章主要介紹了C# 實現(xiàn)截圖軟件功能實例代碼,需要的朋友可以參考下
    2017-06-06
  • .NET6實現(xiàn)分布式定時任務(wù)的完整方案

    .NET6實現(xiàn)分布式定時任務(wù)的完整方案

    這篇文章主要為大家詳細(xì)介紹了.NET6實現(xiàn)分布式定時任務(wù)的完整方案,文中的示例代碼講解詳細(xì),具有一定的借鑒價值,有需要的小伙伴可以參考一下
    2025-04-04
  • C#自定義的字符串操作增強類實例

    C#自定義的字符串操作增強類實例

    這篇文章主要介紹了C#自定義的字符串操作增強類,涉及C#操作字符串實現(xiàn)分割、轉(zhuǎn)換、去重等常用技巧,非常具有實用價值,需要的朋友可以參考下
    2015-03-03
  • C# using()的使用方法

    C# using()的使用方法

    本文主要介紹了C# using()的使用方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2023-02-02
  • C#中類與接口的區(qū)別個人總結(jié)

    C#中類與接口的區(qū)別個人總結(jié)

    這篇文章主要介紹了C#中類與接口的區(qū)別個人總結(jié),本文講解了類與接口的區(qū)別、接口的用處主要體現(xiàn)在下面幾個方面、一些接口的疑問等內(nèi)容,需要的朋友可以參考下
    2015-06-06
  • c#可以創(chuàng)建任意控件的拖動方法

    c#可以創(chuàng)建任意控件的拖動方法

    下面小編就為大家分享一篇c#可以創(chuàng)建任意控件的拖動方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-03-03
  • C#借助Free?Spire.PDF?for?.NET實現(xiàn)輕松提取PDF文本

    C#借助Free?Spire.PDF?for?.NET實現(xiàn)輕松提取PDF文本

    在日常辦公和開發(fā)中,從 PDF 文件中提取文本是一項高頻需求,本文將介紹如何使用免費庫 Free Spire.PDF for .NET 輕松實現(xiàn) PDF 文本提取,感興趣的小伙伴可以了解下
    2026-03-03

最新評論

郸城县| 黔南| 万全县| 深圳市| 梓潼县| 京山县| 醴陵市| 长葛市| 隆化县| 通江县| 上犹县| 安达市| 高陵县| 民权县| 乌拉特前旗| 黄龙县| 南雄市| 来安县| 日土县| 桃江县| 涿州市| 玉山县| 钟山县| 莲花县| 通江县| 彭水| 安陆市| 宝兴县| 枣强县| 清流县| 广宁县| 宽甸| 建湖县| 中方县| 稻城县| 绥棱县| 华安县| 祁阳县| 叶城县| 达孜县| 专栏|