“WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его” Ответ

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его

private void button1_Click(object sender, EventArgs e)
{
    // To keep the user from repeatedly pressing the button, let's disable it
    button1.Enabled = false;

    // Capture the current text ("ABC" in your example)
    string originalText = label1.Text;

    // Create a background worker to sleep for 2 seconds...
    var backgroundWorker = new BackgroundWorker();
    backgroundWorker.DoWork += (s, ea) => Thread.Sleep(TimeSpan.FromSeconds(2));

    // ...and then set the text back to the original when the sleep is done
    // (also, re-enable the button)
    backgroundWorker.RunWorkerCompleted += (s, ea) =>
    {
        label1.Text = originalText;
        button1.Enabled = true;
    };

    // Set the new text ("CDE" in your example)
    label1.Text = "CDE";

    // Start the background worker
    backgroundWorker.RunWorkerAsync();
}
Khaldoun Kalash

Ответы похожие на “WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его”

Вопросы похожие на “WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его”

Больше похожих ответов на “WPF изменить содержание кнопки, подождите 5 секунды, а затем снова измените его” по C#

Смотреть популярные ответы по языку

Смотреть другие языки программирования