在Form1.Load中显示消息框时,图标不会更新

时间:2013-06-16 21:24:06

标签: c# winforms visual-studio visual-studio-2012

在Form1.Load中,我有:

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

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

pcture1

按OK后,它会变为图标:

picture2

如何在启动时进行更新?

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

picture3

整个“加载”功能:

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

,都会这样做

1 个答案:

答案 0 :(得分: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)); 
}