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

C#在窗體中設(shè)計(jì)滾動(dòng)字幕的方法

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

1.涉及到的知識(shí)點(diǎn)

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

(1)Timer組件

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

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

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

public virtual bool Enabled {get;set;}
參數(shù)說明
屬性值:如果計(jì)時(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)啟動(dòng)和關(guān)閉Timer計(jì)時(shí)器

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

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

2. 實(shí)例

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

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

//------------------------------------------------------------------------------
// <auto-generated>
//     此代碼由工具生成。
//     運(yùn)行時(shí)版本:4.0.30319.42000
//
//     對(duì)此文件的更改可能會(huì)導(dǎo)致不正確的行為,并且如果
//     重新生成代碼,這些更改將會(huì)丟失。
// </auto-generated>
//------------------------------------------------------------------------------
 
namespace _188.Properties {
    using System;
    
    
    /// <summary>
    ///   一個(gè)強(qiáng)類型的資源類,用于查找本地化的字符串等。
    /// </summary>
    // 此類是由 StronglyTypedResourceBuilder
    // 類通過類似于 ResGen 或 Visual Studio 的工具自動(dòng)生成的。
    // 若要添加或移除成員,請(qǐng)編輯 .ResX 文件,然后重新運(yùn)行 ResGen
    // (以 /str 作為命令選項(xiàng)),或重新生成 VS 項(xiàng)目。
    [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 實(shí)例。
        /// </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 屬性,對(duì)
        ///   使用此強(qiáng)類型資源類的所有資源查找執(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è)計(jì)

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 = "窗體中滾動(dòng)字幕";
            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è)計(jì)

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

(4) 生成效果

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

相關(guān)文章

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

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

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

    C#多線程及同步示例簡(jiǎn)析

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

    C# 枚舉的使用簡(jiǎn)介

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

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

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

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

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

    C#自定義的字符串操作增強(qiáng)類實(shí)例

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

    C# using()的使用方法

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

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

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

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

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

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

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

最新評(píng)論

如皋市| 靖宇县| 玉山县| 苍梧县| 包头市| 双城市| 浪卡子县| 延寿县| 白朗县| 雷波县| 彩票| 安阳市| 泾源县| 兴义市| 绵阳市| 龙陵县| 开原市| 重庆市| 沾化县| 崇阳县| 吉首市| 昌宁县| 都昌县| 灌云县| 信丰县| 武宁县| 皋兰县| 江西省| 天柱县| 肇州县| 台北县| 霍州市| 武乡县| 横山县| 柳林县| 洮南市| 东山县| 门头沟区| 河津市| 上栗县| 平乐县|