instance does not exist in the current context
-
I'm create an instance called shtb like this: public form1() { InitializeComponent(); SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox(); ... } Later in the script, i tried to use the instance shtb like this: static string strMyOriginalScript = ""; private void form1_Load(object sender, System.EventArgs e) { strMyOriginalScript = shtb.Text; } When ever i try to build the solution, i keep getting the error: 'Editing Area' does not exist in the current context Where im i going wrong? Can anyone help me with atleast this?
-
I'm create an instance called shtb like this: public form1() { InitializeComponent(); SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox(); ... } Later in the script, i tried to use the instance shtb like this: static string strMyOriginalScript = ""; private void form1_Load(object sender, System.EventArgs e) { strMyOriginalScript = shtb.Text; } When ever i try to build the solution, i keep getting the error: 'Editing Area' does not exist in the current context Where im i going wrong? Can anyone help me with atleast this?
-
I'm create an instance called shtb like this: public form1() { InitializeComponent(); SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox(); ... } Later in the script, i tried to use the instance shtb like this: static string strMyOriginalScript = ""; private void form1_Load(object sender, System.EventArgs e) { strMyOriginalScript = shtb.Text; } When ever i try to build the solution, i keep getting the error: 'Editing Area' does not exist in the current context Where im i going wrong? Can anyone help me with atleast this?
the problem is with the object not with the string, define the object outside the constructor, just below the definition of the class public class form1 { SyntaxHighlightingTextBox shtb = null; .................. ............. ... and then in the constructor you initialize the object public form1() { InitializeComponent(); shtb = new SyntaxHighlightingTextBox(); ... Andres
"Learn from the mistakes of others. You can't live long enough to make them all yourself." "Failure doesn't mean I'm a failure, It does mean I have not yet succeeded; Failure doesn't mean that I should give up, It does mean that I should try harder; Failure doesn't mean that I will never make it, It does mean that I need more practice". Thank you for helping.
-
I'm create an instance called shtb like this: public form1() { InitializeComponent(); SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox(); ... } Later in the script, i tried to use the instance shtb like this: static string strMyOriginalScript = ""; private void form1_Load(object sender, System.EventArgs e) { strMyOriginalScript = shtb.Text; } When ever i try to build the solution, i keep getting the error: 'Editing Area' does not exist in the current context Where im i going wrong? Can anyone help me with atleast this?
Latheesan wrote:
SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox();
If this is a control, you need to set it's location on the form and add it to the forms Controls collection. Otherwise, it's just a local variable that disappears as soon as it goes out of scope. Even if it was a member, if it's not in the Controls collection, it's not on the form
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
-
Latheesan wrote:
SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox();
If this is a control, you need to set it's location on the form and add it to the forms Controls collection. Otherwise, it's just a local variable that disappears as soon as it goes out of scope. Even if it was a member, if it's not in the Controls collection, it's not on the form
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
Yes, it was a control that was provided from an external .dll so, i added the dll into my project reference first and then, in the top of the form1.cs, i have this code: using SyntaxHighlighting; and iniside the form1_Load(); i have this code now: Controls.Add(shtb); Yet, i still get that error "The name 'shtb' does not exist in the current context"
-
I'm create an instance called shtb like this: public form1() { InitializeComponent(); SyntaxHighlightingTextBox shtb = new SyntaxHighlightingTextBox(); ... } Later in the script, i tried to use the instance shtb like this: static string strMyOriginalScript = ""; private void form1_Load(object sender, System.EventArgs e) { strMyOriginalScript = shtb.Text; } When ever i try to build the solution, i keep getting the error: 'Editing Area' does not exist in the current context Where im i going wrong? Can anyone help me with atleast this?
Wow... nobody here knew the answer, after 3 hours of tedious research, i finally came to this solution: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=523645&SiteID=1[^] I hope this will helpe someone out here with the same problem as me.
-
Yes, it was a control that was provided from an external .dll so, i added the dll into my project reference first and then, in the top of the form1.cs, i have this code: using SyntaxHighlighting; and iniside the form1_Load(); i have this code now: Controls.Add(shtb); Yet, i still get that error "The name 'shtb' does not exist in the current context"
The error that was pointed out to you is still the case. If you create it in your constructor, locally, then it doesn't exist anymore in your load event. You should call the constructor in your load event. Scratch that. You buy a book on VB.NET, read it, work through it, and start another project when you've learned some basics. If you don't understand variable scoping, you frankly should not be writing code, sorry.
Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )