FORM VISIBLE QUESTION

G

Guest

How can i make my form invisible


public class Form1 : System.Windows.Forms.Form



static void Main()

{

Application.Run(new Form1());


Form1.Visible=false;


}

It returns

An object reference is required for the nonstatic field, method, or property
'System.Windows.Forms.Control.Visible'

I have
using System.Windows.Forms;

too

How can i make invisible my form ?
 
M

Marc Gravell

Various things here...
Form1 is the class not the instance... you need to make the *instance*
invisible.
Application.Run() won't return until the form has finished.

So; what exactly do you want to do... have a permenant invisible form? or
juts hide (close) the form e.g. on a button click? or what?

Marc
 
M

Martijn Mulder

I want that When
my application starts i need to have invisible form






//class InvisibleForm
class InvisibleForm:System.Windows.Forms.Form
{

//constructor
InvisibleForm()
{
WindowState=System.Windows.Forms.FormWindowState.Minimized;
}

//Main
[System.STAThread]
static void Main()
{
System.Windows.Forms.Application.Run(new InvisibleForm());
}
}
 
G

Guest

I dont want to have minimized Form ..

I want to have a form which not visible any part of the screen.

It is easy in Vb. I want to have a command like Form1.visible=false in VB ?
 
P

Peter Duniho

I dont want to have minimized Form ..

I want to have a form which not visible any part of the screen.

It is easy in Vb. I want to have a command like Form1.visible=false in VB
?

Marc already explained the problem with the code you posted to you.

The code you posted doesn't modify the form instance...it incorrectly
attempts to modify the class itself. You need to modify the form instance
if you want to change the Visible property of your form.

To do this, obviously you need two things:

* The reference to the instance
* Time to execute the code

As has been pointed out, the Run method won't return until the form has been
closed, so setting Visible in code after calling the Run method won't work
(even if you were setting the property on the instance, rather than using
the incorrect syntax you've got now). To manage the second item above, you
need to put the code to set the Visible property somewhere that will be run
before the form would actually be used. For example, the handler for the
Load event of the form.

If you put the code to set the Visible property in the handler for the Load
event, then getting the reference is easy. The handler would be a method
inside the form's class itself, and thus the Visible property is immediately
available to you, resolving the first item above:

void Form1_Load(object obj, EventArgs e)
{
Visible = false;
}

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top