Keyword this not available in the current context

G

Guest

Hi

I'm trying to use Rockford Lhotka's "Implementing a Background Process in Visual Basic .NET" in C#" http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09272002.asp.

I have added the Background project in my solution as a VB Project. My UI is in C#. When I try to compile it I get an error saying that "Keyword this is not available in the current context." The line that it errors on is this:

public class Form1 : System.Windows.Forms.Form, IClient
{

------> private Controller m_controller = new Controller(this);

where the constructor for Controller takes a reference to the Client Interface. My Form class inherits from the System.Windows.Forms.Form class and Implements the IClient interface. In VB.NET I do not get this error when I try the following line:

Public Class Form1
Inherits System.Windows.Forms.Form
Implements IClient

Private mController As New Controller(Me)


Can you please tell me how to get this to work in C#.

Thanks

Amit
 
B

Bob Powell [MVP]

Try moving the assignment of the mController into the constructor.

public class Form1 : Form, IClient
{
private Controller mController;

public Form1()
{
mController=new Controller(this);
}

......

}

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml






Amit W. said:
Hi

I'm trying to use Rockford Lhotka's "Implementing a Background Process in
Visual Basic .NET" in C#"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09272002.asp.
I have added the Background project in my solution as a VB Project. My UI
is in C#. When I try to compile it I get an error saying that "Keyword this
is not available in the current context." The line that it errors on is
this:
public class Form1 : System.Windows.Forms.Form, IClient
{

------> private Controller m_controller = new Controller(this);

where the constructor for Controller takes a reference to the Client
Interface. My Form class inherits from the System.Windows.Forms.Form class
and Implements the IClient interface. In VB.NET I do not get this error
when I try the following line:
 
G

Guest

Doh! That worked. Thanks for your help.

Bob Powell said:
Try moving the assignment of the mController into the constructor.

public class Form1 : Form, IClient
{
private Controller mController;

public Form1()
{
mController=new Controller(this);
}

......

}

--
Bob Powell [MVP]
Visual C#, System.Drawing

The Image Transition Library wraps up and LED style instrumentation is
available in the June of Well Formed for C# or VB programmers
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml







Visual Basic .NET" in C#"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet09272002.asp.
is in C#. When I try to compile it I get an error saying that "Keyword this
is not available in the current context." The line that it errors on is
this:
Interface. My Form class inherits from the System.Windows.Forms.Form class
and Implements the IClient interface. In VB.NET I do not get this error
when I try the following line:
 

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