欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#實(shí)現(xiàn)動(dòng)態(tài)圖標(biāo)閃爍顯示的示例代碼

 更新時(shí)間:2022年12月14日 11:38:54   作者:芝麻粒兒  
這篇文章主要為大家詳細(xì)介紹了如何利用C#實(shí)現(xiàn)動(dòng)態(tài)圖標(biāo)閃爍顯示的功能,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)C#有一定的幫助,感興趣的小伙伴可以了解一下

實(shí)踐過程

效果

代碼

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    private Thread td;
    private TcpListener tcpListener;
    string message="";
    private void Form1_Load(object sender, EventArgs e)
    {
        td = new Thread(new ThreadStart(this.StartListen));
        td.Start();
    }

    private void StartListen()
    {
        tcpListener = new TcpListener(888);
        tcpListener.Start();
        while (true)
        {
            TcpClient tclient = tcpListener.AcceptTcpClient();  //接受連接請(qǐng)求
            NetworkStream nstream = tclient.GetStream();        //獲取數(shù)據(jù)流
            byte[] mbyte = new byte[1024];                      //建立緩存
            int i = nstream.Read(mbyte, 0, mbyte.Length);       //將數(shù)據(jù)流寫入緩存
            message = Encoding.Default.GetString(mbyte, 0, i);
        }
    }

    private void Form1_FormClosed(object sender, FormClosedEventArgs e)
    {
        if (this.tcpListener != null)
        {
            tcpListener.Stop();
        }
        if (td != null)
        {
            if (td.ThreadState == ThreadState.Running)
            {
                td.Abort();
            }
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        try
        {
            IPAddress[] ip = Dns.GetHostAddresses(Dns.GetHostName());
            string message ="你好兄弟";
            TcpClient client = new TcpClient(txtAdd.Text, 888);
            NetworkStream netstream = client.GetStream();
            StreamWriter wstream = new StreamWriter(netstream, Encoding.Default);
            wstream.Write(message);
            wstream.Flush();
            wstream.Close();
            client.Close();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

    bool k = true;
    private void timer1_Tick(object sender, EventArgs e)
    {
        if (message.Length > 0)
        {
            if (k)
            {
                notifyIcon1.Icon = Properties.Resources._1;
                k = false;
            }
            else
            {
                notifyIcon1.Icon = Properties.Resources._2;
                k = true;
            }
        }
    }

    private void button2_Click(object sender, EventArgs e)
    {
        message = "";
        notifyIcon1.Icon = Properties.Resources._3;
    }
}
partial class Form1
{
    /// <summary>
    /// 必需的設(shè)計(jì)器變量。
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// 清理所有正在使用的資源。
    /// </summary>
    /// <param name="disposing">如果應(yīng)釋放托管資源,為 true;否則為 false。</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows 窗體設(shè)計(jì)器生成的代碼

    /// <summary>
    /// 設(shè)計(jì)器支持所需的方法 - 不要
    /// 使用代碼編輯器修改此方法的內(nèi)容。
    /// </summary>
    private void InitializeComponent()
    {
        this.components = new System.ComponentModel.Container();
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
        this.timer1 = new System.Windows.Forms.Timer(this.components);
        this.txtAdd = new System.Windows.Forms.TextBox();
        this.button1 = new System.Windows.Forms.Button();
        this.label1 = new System.Windows.Forms.Label();
        this.groupBox1 = new System.Windows.Forms.GroupBox();
        this.button2 = new System.Windows.Forms.Button();
        this.groupBox1.SuspendLayout();
        this.SuspendLayout();
        // 
        // notifyIcon1
        // 
        this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
        this.notifyIcon1.Visible = true;
        // 
        // timer1
        // 
        this.timer1.Enabled = true;
        this.timer1.Interval = 500;
        this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
        // 
        // txtAdd
        // 
        this.txtAdd.Location = new System.Drawing.Point(145, 36);
        this.txtAdd.Name = "txtAdd";
        this.txtAdd.Size = new System.Drawing.Size(193, 21);
        this.txtAdd.TabIndex = 0;
        // 
        // button1
        // 
        this.button1.Location = new System.Drawing.Point(103, 96);
        this.button1.Name = "button1";
        this.button1.Size = new System.Drawing.Size(75, 23);
        this.button1.TabIndex = 1;
        this.button1.Text = "發(fā)送消息";
        this.button1.UseVisualStyleBackColor = true;
        this.button1.Click += new System.EventHandler(this.button1_Click);
        // 
        // label1
        // 
        this.label1.AutoSize = true;
        this.label1.Location = new System.Drawing.Point(26, 39);
        this.label1.Name = "label1";
        this.label1.Size = new System.Drawing.Size(113, 12);
        this.label1.TabIndex = 2;
        this.label1.Text = "輸入對(duì)方主機(jī)地址:";
        // 
        // groupBox1
        // 
        this.groupBox1.Controls.Add(this.button2);
        this.groupBox1.Controls.Add(this.button1);
        this.groupBox1.Controls.Add(this.label1);
        this.groupBox1.Controls.Add(this.txtAdd);
        this.groupBox1.Location = new System.Drawing.Point(13, 13);
        this.groupBox1.Name = "groupBox1";
        this.groupBox1.Size = new System.Drawing.Size(353, 154);
        this.groupBox1.TabIndex = 3;
        this.groupBox1.TabStop = false;
        this.groupBox1.Text = "發(fā)送消息";
        // 
        // button2
        // 
        this.button2.Location = new System.Drawing.Point(184, 96);
        this.button2.Name = "button2";
        this.button2.Size = new System.Drawing.Size(75, 23);
        this.button2.TabIndex = 3;
        this.button2.Text = "停止閃動(dòng)";
        this.button2.UseVisualStyleBackColor = true;
        this.button2.Click += new System.EventHandler(this.button2_Click);
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(380, 182);
        this.Controls.Add(this.groupBox1);
        this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
        this.MaximizeBox = false;
        this.MinimizeBox = false;
        this.Name = "Form1";
        this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        this.Text = "動(dòng)態(tài)托盤圖標(biāo)";
        this.Load += new System.EventHandler(this.Form1_Load);
        this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.Form1_FormClosed);
        this.groupBox1.ResumeLayout(false);
        this.groupBox1.PerformLayout();
        this.ResumeLayout(false);

    }

    #endregion

    private System.Windows.Forms.NotifyIcon notifyIcon1;
    private System.Windows.Forms.Timer timer1;
    private System.Windows.Forms.TextBox txtAdd;
    private System.Windows.Forms.Button button1;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.GroupBox groupBox1;
    private System.Windows.Forms.Button button2;
}

以上就是C#實(shí)現(xiàn)動(dòng)態(tài)圖標(biāo)閃爍顯示的示例代碼的詳細(xì)內(nèi)容,更多關(guān)于C#動(dòng)態(tài)圖標(biāo)閃爍顯示的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • c# 如何用lock解決緩存擊穿

    c# 如何用lock解決緩存擊穿

    這篇文章主要介紹了c# 如何用lock解決緩存擊穿,幫助大家更好的理解和使用c#,感興趣的朋友可以了解下
    2021-02-02
  • C#求n個(gè)數(shù)中最大值和最小值的方法

    C#求n個(gè)數(shù)中最大值和最小值的方法

    這篇文章主要介紹了C#求n個(gè)數(shù)中最大值和最小值的方法,涉及C#中max及min方法的使用技巧,需要的朋友可以參考下
    2015-05-05
  • C#使用HtmlAgilityPack組件解析html文檔

    C#使用HtmlAgilityPack組件解析html文檔

    這篇文章介紹了C#使用HtmlAgilityPack組件解析html文檔的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-06-06
  • 簡(jiǎn)單聊聊C#的線程本地存儲(chǔ)TLS到底是什么

    簡(jiǎn)單聊聊C#的線程本地存儲(chǔ)TLS到底是什么

    C#的ThreadStatic是假的,因?yàn)镃#完全是由CLR(C++)承載的,言外之意C#的線程本地存儲(chǔ),用的就是用C++運(yùn)行時(shí)提供的 __declspec(thread)或__thread來虛構(gòu)的一套玩法,下面我們就來深入講講C#的線程本地存儲(chǔ)TLS到底是什么吧
    2024-01-01
  • C#操作INI文件的示例代碼

    C#操作INI文件的示例代碼

    這篇文章主要為大家詳細(xì)介紹了C#操作INI文件的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨上班一起學(xué)習(xí)一下
    2023-12-12
  • C#中窗體重復(fù)創(chuàng)建問題的解決方法

    C#中窗體重復(fù)創(chuàng)建問題的解決方法

    在C#Windows窗體應(yīng)用中,我們經(jīng)常遇到這樣的問題,當(dāng)我們觸發(fā)一個(gè)窗口命令時(shí),我連續(xù)點(diǎn)擊其中一個(gè)命令,會(huì)出現(xiàn)多個(gè)同樣的窗口,但我們是不管點(diǎn)擊多少次,都只出現(xiàn)一次,所以本文給大家介紹了C#中窗體重復(fù)創(chuàng)建問題的解決方法,需要的朋友可以參考下
    2024-04-04
  • 如何利用現(xiàn)代化C#語法簡(jiǎn)化代碼

    如何利用現(xiàn)代化C#語法簡(jiǎn)化代碼

    這篇文章主要給大家介紹了關(guān)于如何利用現(xiàn)代化C#語法簡(jiǎn)化代碼的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • C#設(shè)計(jì)模式之Mediator中介者模式解決程序員的七夕緣分問題示例

    C#設(shè)計(jì)模式之Mediator中介者模式解決程序員的七夕緣分問題示例

    這篇文章主要介紹了C#設(shè)計(jì)模式之Mediator中介者模式解決程序員的七夕緣分問題,簡(jiǎn)單說明了中介者模式的定義并結(jié)合七夕緣分問題實(shí)例分析了中介者模式的具體使用技巧,需要的朋友可以參考下
    2017-09-09
  • C#表達(dá)式中的動(dòng)態(tài)查詢?cè)斀狻咀g】

    C#表達(dá)式中的動(dòng)態(tài)查詢?cè)斀狻咀g】

    這篇文章主要給大家介紹了關(guān)于C#表達(dá)式中動(dòng)態(tài)查詢的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-01-01
  • C#實(shí)現(xiàn)將窗體固定在顯示器的左上角且不能移動(dòng)的方法

    C#實(shí)現(xiàn)將窗體固定在顯示器的左上角且不能移動(dòng)的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)將窗體固定在顯示器的左上角且不能移動(dòng)的方法,涉及C#窗體固定操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-08-08

最新評(píng)論