The IDE knows about the Form1 type. It doesn't need to create a
design-time instance, it just is aware of the metadata that defines
those types. (The designer probably does create a design time instance,
but that's separate from the code editor AFAIK).
At any rate ... I don't understand your final question, "I ... don't ...
get why I cannot perform ... Form1.label1.Te xt = "foo"". If that wasn't
a slip of the keyboard then I must return to my original explanation:
Form1 is a type, not an instance. The only thing you can access through
the type are static members. Instance members must be addressed through
an instance. Form1.label1 is not a valid construct because label1 is an
instance member.
If on the other hand you're asking (given a Form1 instance named myForm)
why "myForm." doesn't auto-complete, but "myForm.label1. " *does* offer
you auto-complete options -- I don't know offhand. I've seen stuff like
this intermittently and just chalk it up to One Of Those Things.
Sometimes it clears up on its own (because some background parsing
thread caught up with what you're typing) and sometimes it Just Won't
Work, At Least Not Today.
--Bob
Liz wrote:
"Bob Grommes" <bo*@bobgrommes .com> wrote in message
If label1 is still declared as a public field, myForm.label1 should be
able to be referenced. Don't conclude it's not from the absence of
Intellisens e, in my experience that's only 80% reliable until the
project has had a recompile (or sometimes it starts working on its own
after some IDE background thread has caught up with reality). It's not
a good sign though. Is code completion failing in Main() or somewhere
else?
You can always test by putting some dummy reference in Main() like
myForm.label1 .Text = "foo";
sure .. and that works, in the Class block, anyway .. but not in the other
.cs file which references the namespace containing the class Form1 ...
I still don't really get why I cannot perform the same test with
Form1.label1.Te xt = "foo"; ... what's the deal ? does the **IDE** actually
create an instance of the class when you type in Form1 myform = new Form1()
?? and if it hasn't seen a "new" yet it doesn't know that label1 is a
member of the class ?
static void Main()
{
myForm.label1. .... // code completion does not work here
Form1 myForm = new Form1();
myForm.label1.T ext = "XXX"; // but works here ...
Application.Run (myForm);
}
L