0

在 Form1.Load 中,我有:

MessageBox.Show("Text blah blah blah");

在您按 OK 之前,这是任务栏中的图标:

图1

当您按 OK 时,它会变为图标:

图2

如何让它在启动时更新?

我通过在表单属性中更改图标来更改它:

图3

整个“加载”功能:

string word = "1.4";

var url = "http://chipperyman573.com/rtf/textbot.html";
var client = new WebClient();
using (var stream = client.OpenRead(url))
using (var reader = new StreamReader(stream))
{
    string downloadedString;
    while ((downloadedString = reader.ReadLine()) != null)
    {
        if (downloadedString == word)
        {
            update = false;
            MessageBox.Show("Congrats! You are running the latest version (" + word + ") of Chip Bot!\n\nGot an idea for this program? Use the \"Send feedback\" button to let me know!", "Chip Bot", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Text = "Chip Bot" + word + " - Got an idea for this program? Send me some feedback!";
        }
        else
        {
            Text = "Chip Bot (UPDATE AVAILABLE)";
            go.ForeColor = Color.Gray;
            setup.Enabled = false;
            otherGroup.Enabled = false;
            optionsGroup.Enabled = false;
            MessageBox.Show("There is an update! Downloading now! \n\nUNTIL YOU UPDATE THE PROGRAM WILL NOT FUNCTION.", "Chip Bot", MessageBoxButtons.OK, MessageBoxIcon.Information);
            url = "";
            var web = new WebBrowser();
            web.Navigate(url);
        }
    }
}

无论是否有更新 ( downloadstring != word) 或没有更新 ( downloadstring == word)它都会执行此操作

4

1 回答 1

1

尝试改用该Shown事件,并且我使用错误使用WebClient(我使用了DownloadStringAsync)修复了您的代码:

private void Form1_Shown(Object s1, EventArgs e1) {
    string word = "1.4";

    var url = "http://chipperyman573.com/rtf/textbot.html";
    var client = new WebClient();

    client.DownloadStringCompleted += (s2, e2) => 
    {
       if(e2.Error != null)
       {
            //Maybe do some error handling?
       }
       else
       {
            if (e2.Result == word)
            {
                update = false;
                MessageBox.Show("Congrats! You are running the latest version (" + word + ") of Chip Bot!\n\nGot an idea for this program? Use the \"Send feedback\" button to let me know!", "Chip Bot", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Text = "Chip Bot" + word + " - Got an idea for this program? Send me some feedback!";
            }
            else
            {
                Text = "Chip Bot (UPDATE AVAILABLE)";
                go.ForeColor = Color.Gray;
                setup.Enabled = false;
                otherGroup.Enabled = false;
                optionsGroup.Enabled = false;
                MessageBox.Show("There is an update! Downloading now! \n\nUNTIL YOU UPDATE THE PROGRAM WILL NOT FUNCTION.", "Chip Bot", MessageBoxButtons.OK, MessageBoxIcon.Information);
                url = "";
                var web = new WebBrowser();
                web.Navigate(url);
            }
       }
    };

    client.DownloadStringAsync(new Uri(url, UriKind.Absolute)); 
}
于 2013-06-16T21:46:13.947 回答