I'm busy with a project in C# that involves 2 Windows Form. The program asks to user to enter a topic in a textbar and then the user selects from 3 websites to search and display a video.
This is the code from the first form,
private void btnSearch_Click(object sender, EventArgs e)
{
//Assign Search
Search = SearchBox.Text;
//Assign Website
if (rb1YouTube.Checked)
{
WebSite = 1;
}
else if (rb2MetaCafe.Checked)
{
WebSite = 2;
}
else if (rb3Yahoo.Checked)
{
WebSite = 3;
}
//Assign Category
Category = " - " + cbCategory.Text;
//Input Validation
if (Search == "" || Category == " - " || WebSite == 0)
{
System.Windows.Forms.MessageBox.Show("All fields require values");
}
else
{
//Declare class and pass variables
Results RF = new Results(Search, WebSite, Category);
RF.Show();
}
}
And here is the code from the second.
public Results(String Search, int WebSite, String Category)
{
try
{
switch (WebSite)
{
case 1: webBrowser1.Navigate("https://www.youtube.com/");
break;
case 2: webBrowser1.Navigate("http://www.metacafe.com/");
break;
case 3: webBrowser1.Navigate("https://screen.yahoo.com/");
break;
}
}
catch(Exception E)
{
MessageBox.Show(" " + E);
}
InitializeComponent();
}
The error occurs when the values are passed into the new form, after its run through the switch/case.
I have debugged the program and had a breakpoint on the public Results(String Search, int WebSite, String Category)
line, I've ensured the values are being sent and received.