473,396 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Keyword this not available in the current context

Hi

I'm trying to use Rockford Lhotka's "Implementing a Background Process in Visual Basic .NET" in C#" http://msdn.microsoft.com/library/de...et09272002.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
Nov 16 '05 #1
2 10308
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." <Amit W.@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
Hi

I'm trying to use Rockford Lhotka's "Implementing a Background Process in Visual Basic .NET" in C#"
http://msdn.microsoft.com/library/de...et09272002.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

Nov 16 '05 #2
Doh! That worked. Thanks for your help.

"Bob Powell [MVP]" wrote:
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." <Amit W.@discussions.microsoft.com> wrote in message
news:8F**********************************@microsof t.com...
Hi

I'm trying to use Rockford Lhotka's "Implementing a Background Process in

Visual Basic .NET" in C#"
http://msdn.microsoft.com/library/de...et09272002.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


Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: brian.bird | last post by:
Can anyone explain the behaviour of python when running this script? >>> def method(n, bits=): .... bits.append(n) .... print bits .... >>> method(1) >>> method(2)
13
by: DarkSpy | last post by:
many c++ compilers including "gcc" have not implemented the "export" keyword, but the comeau compilers made it (just i knew). i want to know about: is it too difficult to implement "export"...
0
by: Perry Shindle | last post by:
Does anyone no where I can get the latest, up-to-date list of valid values for the CLI PATCH2 keyword? I followed the current link in the on-line DB2 UDB Information Center and it led me to PATCH2...
16
by: vaughn | last post by:
What is the 'this' keyeword for? If I'm filling a textbox, what's the difference between this.textbox1.Text = "my text"; and textbox1.Text = "my text"; ? I normally use it w/o the 'this'. Thanks.
4
by: PauloFor | last post by:
In this code : public abstract class DCMenuAgrupado { Object x = this; }
5
by: ChrisB | last post by:
Hello: An object that is a field in another object has a constructor that requires a reference to the containing object: // object fields ChildObject childObject = new ChildObject(this); ...
5
by: Polaris431 | last post by:
I notice that the Dataset designer generates code for properties that look like this: public string ID { get { try { return ((string) (this)); } catch (System.InvalidCastException e) {
1
by: alamodgal | last post by:
hiiiiiii I have a problem in highlighting searching keyword.Actually im using this function for searching Public Function HighLight(ByVal Keyword As String, ByVal ContentFor As String) Dim...
2
by: ChaosMageX | last post by:
I copied some code from a Mono 2.4 library to use in my own application. I'm getting a problem because one of the variable declarations involves the keyword "pinned" between the identifier and the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.