Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. instance does not exist in the current context

instance does not exist in the current context

Scheduled Pinned Locked Moved C#
helptoolsquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Latheesan
    wrote on last edited by
    #1

    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?

    L A C 4 Replies Last reply
    0
    • L Latheesan

      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?

      L Offline
      L Offline
      Latheesan
      wrote on last edited by
      #2

      I tried editing like this also: static string strMyOriginalScript = ""; private void form1_Load(object sender, System.EventArgs e) { SyntaxHighlightingTextBox shtb; strMyOriginalScript = shtb.Text; } still didn't work... where im i going wrong?

      1 Reply Last reply
      0
      • L Latheesan

        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?

        A Offline
        A Offline
        andreshs1
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • L Latheesan

          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?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          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 )

          L 1 Reply Last reply
          0
          • C Christian Graus

            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 )

            L Offline
            L Offline
            Latheesan
            wrote on last edited by
            #5

            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"

            C 1 Reply Last reply
            0
            • L Latheesan

              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?

              L Offline
              L Offline
              Latheesan
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • L Latheesan

                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"

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                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 )

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups