简体   繁体   English

几秒钟后如何使TextBlock不可见?

[英]How to make invisible a TextBlock after a few seconds?

您能否告诉我,是否可以在几秒钟后使TextBlock不可见,或者即使未在控件HUB中声明TextBlock,也看到其他HubSection吗?

using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        Timer tmr;

        public Form1()
        {
            InitializeComponent();

            tmr = new Timer();
            tmr.Interval = 3 * 1000; // 3 seconds
            tmr.Tick += new EventHandler(tmr_Tick);
            tmr.Start();
        }

        void tmr_Tick(object sender, EventArgs e)
        {
            label1.Visible = false;
            tmr.Stop();
        }
    }
}

In WPF, you can use a DispatcherTimer to do the same thing: 在WPF中,可以使用DispatcherTimer进行相同的操作:

System.Windows.Threading.DispatcherTimer myDispatcherTimer = new System.Windows.Threading.DispatcherTimer();
myDispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); // 100 Milliseconds 
myDispatcherTimer.Tick += new EventHandler(tmr_Tick);
myDispatcherTimer.Start();


public void tmr_Tick(object o, EventArgs sender)
{
    myTextBlock.Text = "test";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM