在Form1.Load中,我有:
MessageBox.Show("Text blah blah blah");
在按OK之前,这是任务栏中的图标:
按OK后,它会变为图标:
如何在启动时进行更新?
我通过在表单属性中更改图标来更改图标:
整个“加载”功能:
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
)
答案 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));
}