simple C# question

  • Thread starter Thread starter makai
  • Start date Start date
M

makai

Guest
OK - I put a label on a form in C# - then I added this code (the event code was added automatically simply by clicking the label in the designer) I just added label1.text = "test";:



private void label1_Click(object sender, System.EventArgs e)
{
label1.text = "test";
}


incredibly the project will not build - it underlines label1.text and says:

System.Windows.Forms.Control.text is inaccessible due to its protection level.


can someone tell me what is going on and how to make it work?
 
I had the same problem for a second.

The problem is that you have to capitalize the T in the Text:

label1.Text = "test";
 
The Intellisense in C# is not as intelligent as in VB.NET. You need to pay more attention as you type.
 
I think its the same in both, its just that VB.NET isnt case-sensitive whereas C# is. It can be a pain if you dont know whats going on :)

I use the Tab key to have intellisense auto-complete for me and it adjusts capitalization automatically. Another trick is to press Ctrl-Space to have the autocomplete either fill in the rest of your word, or bring up the intellisense drop-down so you can pick what you want (and press tab to have it fill it in). I got used to that in VB6 and its worked wonders ever since.

-nerseus
 
Actually, C#s intellisense isnt as intelligent as VBs; for example,
the using statement doesnt invoke the the intellisense,
while Imports in VB.NET does. Also, in some cases when
working with classes, this, among other things, dont have
intellisense either.

Apparently this is fixed in VB.NET 2003.
 
Fixed in VB.NET? You mean C# 2003, or were you being sarcastic in that is now *doesnt* work in VB.NET 2003?

Ive never had trouble using intellisense with "this". Youre right about "using" not having intellisense, but only for the first word. Since you use "System" about 99% of the time, its not such a big deal but it is kind of a pain :) You can also press Ctrl-Space to bring up a list of "using" references, but not many people know about it or want to use it :)

-Nerseus
 
Yeah, Ctrl-Space will complete the word, but at least in VB when you move off the line, it will correct the case as well as the indents, C# does not.

Also, if you have compile errors in C#, then as you fix those errors, the blue line is still there (until you recompile).

Oh, one thing I do prefer in C# is that it will point out (blue line) unused variables.
 
Heh, oops, I meant VS.NET, not VB.NET. But aside from using, there
are still some inconsistencies, which make life harder. I cant tell
you of any right off the top of my head, but I do know that there
are more; it drove me crazy when making a game with GDI+ in C#.

Let me open C# to find some...

...

Ok, here is a major one for me; no autolisting of constants. I type
this.DrawMode = in C#. Nothing happens. No intellisense
list of possible draw modes, so I have to type System.Drawing.DrawModes or whatever the constant
is in order to get the list. In VB.NET I type Me.DrawMode =
and a list of possible constants pops up. Quite a big pain.

Another is that is doesnt do as-you-type error checking for anything
other than structure. I type
C#:
Drawing.Graphics g;

g.MeasureString(a,b,c,d,e)
and there are no errors. Aside from the fact that none of those
variables exist, there arent that many parameters in MeasureString.
 
Yeah, and it will only tell you when you try and compile, and as I said earlier, the blue error line will still be there after you have fixed it.
 
As Volte said, supposedly the Intellisense in C# in VS.NET 2003 has been brought up to par with VBs :)
 
Well, its supposedly going to be a very inexpensive upgrade for
people who already own the first .NET, so yeah. :)
 
I heard $30. Something in that region, definitely. For registered owners of VS.NET, anyway.
 
Back
Top