Reputation: 933
I tried to steal some lines from a similar application. The lines are:
WelcomeScreen screen = form as WelcomeScreen;
if ((screen != null) && (screen.Text == "Channel Bar"))
{
screen.Visible = true;
screen.WindowState = FormWindowState.Normal;
screen.BringToFront();
return;
}
After I enter this, I get the message:
The name 'form' does not exist in the current context
I have:
using System.Windows.Forms;
Isn't form a standard object in C#?
Upvotes: 2
Views: 2970
Reputation: 14967
You don't create a instance of a class that way, you should do it like this:
WelcomeScreen screen = new WelcomeScreen();
Upvotes: 1
Reputation: 97
Assuming WelcomeScreen is a defined class:
WelcomeScreen screen = New WelcomeScreen();
I left out the parentheses.
Upvotes: 2
Reputation: 13805
Your code is expecting a variable named form
. form as WelcomeScreen
is trying to cast an object, form
, to WelcomeScreen
. I don't see a declaration for form
anywhere, hence your error.
If you're inside a form class, you want to use this
, not form
.
If you're just trying to create an instance of WelcomeScreen
, you can simply do:
var screen = new WelcomeScreen();
.
Upvotes: 3