Jump to content
Xtreme .Net Talk

simple C# question


Recommended Posts

Posted

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?

  • 1 month later...
  • *Experts*
Posted

I think it's the same in both, it's just that VB.NET isn't case-sensitive whereas C# is. It can be a pain if you don't know what's 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 it's worked wonders ever since.

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

Actually, C#'s intellisense isn't as intelligent as VB's; for example,

the using statement doesn't invoke the the intellisense,

while Imports in VB.NET does. Also, in some cases when

working with classes, this, among other things, don't have

intellisense either.

 

Apparently this is fixed in VB.NET 2003.

  • *Experts*
Posted

Fixed in VB.NET? You mean C# 2003, or were you being sarcastic in that is now *doesn't* work in VB.NET 2003?

 

I've never had trouble using intellisense with "this". You're right about "using" not having intellisense, but only for the first word. Since you use "System" about 99% of the time, it's 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • Moderators
Posted

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.

Visit...Bassic Software
  • *Experts*
Posted

Heh, oops, I meant VS.NET, not VB.NET. But aside from using, there

are still some inconsistencies, which make life harder. I can't 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 doesn't do as-you-type error checking for anything

other than structure. I type

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 aren't that many parameters in MeasureString.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...