Changing the location of button using programming
-
Does anyone know how to change the location of a button using programming. I'm going to use it to make "simple" and "advanced" options in my search program. Thanks Hengy I like Pie
-
Please don't double post, your old thread is perfectly suited for this question. Anyway, here is the solution:
Button b = new Button();
// ...
b.Location = new Point(10, 10);Sorry for the double post... I have another problem: when the doesn'tpick anything from a combobox, it says: System.NullReferenceException was unhandled but in my code, I put a default setting in my switch. private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked != true) { MessageBox.Show("Search"); } else { switch (comboBox1.SelectedItem.ToString()) { case ("Mininova"): string targetURL = @"http://www.mininova.org"; System.Diagnostics.Process.Start(targetURL); break; case ("TorrentSpy"): string targetURL2 = @"http://www.torrentspy.com"; System.Diagnostics.Process.Start(targetURL2); break; case ("IsoHunt"): string targetURL3 = @"http://www.isohunt.com"; System.Diagnostics.Process.Start(targetURL3); break; case ("MyBitTorrent"): string targetURL4 = @"http://www.mybittorrent.com"; System.Diagnostics.Process.Start(targetURL4); break; default: MessageBox.Show("Please select a website to search."); break; } } } any ideas? thanks for the help... I seem to be asking alot of it today!:confused: Hengy I like Pie
-
Sorry for the double post... I have another problem: when the doesn'tpick anything from a combobox, it says: System.NullReferenceException was unhandled but in my code, I put a default setting in my switch. private void button1_Click(object sender, EventArgs e) { if (checkBox1.Checked != true) { MessageBox.Show("Search"); } else { switch (comboBox1.SelectedItem.ToString()) { case ("Mininova"): string targetURL = @"http://www.mininova.org"; System.Diagnostics.Process.Start(targetURL); break; case ("TorrentSpy"): string targetURL2 = @"http://www.torrentspy.com"; System.Diagnostics.Process.Start(targetURL2); break; case ("IsoHunt"): string targetURL3 = @"http://www.isohunt.com"; System.Diagnostics.Process.Start(targetURL3); break; case ("MyBitTorrent"): string targetURL4 = @"http://www.mybittorrent.com"; System.Diagnostics.Process.Start(targetURL4); break; default: MessageBox.Show("Please select a website to search."); break; } } } any ideas? thanks for the help... I seem to be asking alot of it today!:confused: Hengy I like Pie
If no selection is made, then the target of the switch() statement is null - comboBox1.SelectedItem is uninitialized, so you can't call the ToString() method on it. change the if -else statement to:
if (checkBox1.Checked != true)
{
...
}
else if (checkBox1.SelectedItem != null)
{
switch (comboBox1.SelectedItem.ToString())
{
....
}
}
else
{
MessageBox.Show("Please select a website to search.");
}Last modified: Sunday, June 04, 2006 6:20:40 PM --