Will
Will

Reputation: 1164

Trouble with class in vb.net

I'm creating a label within a class and I'm getting an error when i try to do the following code below where its bold. The error I'm getting is that

Drawing is not declared. It may be due to its protection level.

I'm thinking that I have to import a namespace, but I'm not sure exactly which one contains Drawing. I have researched this and have been unsuccessful. Any help would be very much appreciated.

Label1.ForeColor = Drawing.Color.Red

Upvotes: 2

Views: 898

Answers (3)

Reed Copsey
Reed Copsey

Reputation: 564403

Color is actually System.Drawing.Color.

You can fully qualify it:

lable1.ForeColor = System.Drawing.Color.Red

Alternatively, you can use Imports System.Drawing at the top of your file:

' This needs to be in your imports: Imports System.Drawing
lable1.ForeColor = Color.Red

Upvotes: 3

dbasnett
dbasnett

Reputation: 11773

Creates a label within a class and then changes the ForeColor to red.

    Dim bar As New foo
    bar.myLabel.ForeColor = Color.Red
    'or
    bar.myLabel.ForeColor = Drawing.Color.Red
    'or
    bar.myLabel.ForeColor = System.Drawing.Color.Red



Class foo
    Property myLabel As New Label
End Class

Upvotes: 0

Ry-
Ry-

Reputation: 224905

Do you have a reference to System.Drawing.dll in your project? If you don't, add it using Project > Add Reference. Otherwise, you may need to import System using this statement at the top of your file:

Imports System

Though by default, in a Windows Forms Application, there is a reference to System.Drawing and it's imported, too. Finally, your capitalization is wrong; it should be Label1.ForeColor.

Upvotes: 0

Related Questions