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. Windows Forms
  4. The name does not exist in the current context

The name does not exist in the current context

Scheduled Pinned Locked Moved Windows Forms
graphicsdesignhelplearning
3 Posts 3 Posters 17 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.
  • U Offline
    U Offline
    User 11452013
    wrote on last edited by
    #1

    Hey, I am new to GUI programming While trying to design a dialog box that gets user input and saves it to a file on clicking the save button, I ran into this error. [code] using System.Windows.Forms; using System.Drawing; using System.IO; using System; public class Mfury : Form { public Mfury() { Size = new Size(800,500); Text = "Enter details of the book"; Label xo = new Label(); xo.Text = "Name : "; xo.Location = new Point(10,10); xo.Width = 50; xo.Parent = this; TextBox to = new TextBox(); to.Parent = this; to.Location = new Point(90,10); to.Width = 600; to.Multiline = false; string Var1 = to.Text; Label x1 = new Label(); x1.Text = " ISBN : "; x1.Width = 50; x1.Location = new Point(10,50); x1.Parent = this; TextBox t1 = new TextBox(); t1.Parent = this; t1.Location = new Point(91,43); t1.Width = 600; t1.Multiline = false; string Var2 = t1.Text; Label x2 = new Label(); x2.Text = "Key Words :"; x2.Width = 80; x2.Parent = this; x2.Location = new Point(10,90); TextBox t2 = new TextBox(); t2.Parent = this; t2.Location = new Point(91,83); t2.Width = 600; t2.Multiline = false; string Var3 = t2.Text; Button bo = new Button(); Button b1 = new Button(); bo.Parent = this; b1.Parent = this; bo.Location = new Point(520,350); bo.Text = "Save"; bo.Height = 100; bo.Width = 100; Controls.Add(bo); b1.Location = new Point(630,350); b1.Text = "Close"; b1.Size = new Size(100,100); Controls.Add(b1); bo.Click += new EventHandler(onsave); b1.Click += new EventHandler(onExit); } void onsave(Object Sender,EventArgs e) { FileStream fs = new FileStream("test.txt",FileMode.OpenOrCreate,FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(to.Text); sw.WriteLine(t1.Text); sw.WriteLine(t2.Text); sw.Close(); } void onExit(Object Sender,EventArgs e) { Close(); } public static void Main() { Application.Run(new Mfury()); } } [\code]

    L A 2 Replies Last reply
    0
    • U User 11452013

      Hey, I am new to GUI programming While trying to design a dialog box that gets user input and saves it to a file on clicking the save button, I ran into this error. [code] using System.Windows.Forms; using System.Drawing; using System.IO; using System; public class Mfury : Form { public Mfury() { Size = new Size(800,500); Text = "Enter details of the book"; Label xo = new Label(); xo.Text = "Name : "; xo.Location = new Point(10,10); xo.Width = 50; xo.Parent = this; TextBox to = new TextBox(); to.Parent = this; to.Location = new Point(90,10); to.Width = 600; to.Multiline = false; string Var1 = to.Text; Label x1 = new Label(); x1.Text = " ISBN : "; x1.Width = 50; x1.Location = new Point(10,50); x1.Parent = this; TextBox t1 = new TextBox(); t1.Parent = this; t1.Location = new Point(91,43); t1.Width = 600; t1.Multiline = false; string Var2 = t1.Text; Label x2 = new Label(); x2.Text = "Key Words :"; x2.Width = 80; x2.Parent = this; x2.Location = new Point(10,90); TextBox t2 = new TextBox(); t2.Parent = this; t2.Location = new Point(91,83); t2.Width = 600; t2.Multiline = false; string Var3 = t2.Text; Button bo = new Button(); Button b1 = new Button(); bo.Parent = this; b1.Parent = this; bo.Location = new Point(520,350); bo.Text = "Save"; bo.Height = 100; bo.Width = 100; Controls.Add(bo); b1.Location = new Point(630,350); b1.Text = "Close"; b1.Size = new Size(100,100); Controls.Add(b1); bo.Click += new EventHandler(onsave); b1.Click += new EventHandler(onExit); } void onsave(Object Sender,EventArgs e) { FileStream fs = new FileStream("test.txt",FileMode.OpenOrCreate,FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(to.Text); sw.WriteLine(t1.Text); sw.WriteLine(t2.Text); sw.Close(); } void onExit(Object Sender,EventArgs e) { Close(); } public static void Main() { Application.Run(new Mfury()); } } [\code]

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      What error, and where does it occur? Also, please use <pre> tags around your code, not [code]. You can do it automatically by selecting all the lines in your post, and using the code button at the top of the edit box.

      1 Reply Last reply
      0
      • U User 11452013

        Hey, I am new to GUI programming While trying to design a dialog box that gets user input and saves it to a file on clicking the save button, I ran into this error. [code] using System.Windows.Forms; using System.Drawing; using System.IO; using System; public class Mfury : Form { public Mfury() { Size = new Size(800,500); Text = "Enter details of the book"; Label xo = new Label(); xo.Text = "Name : "; xo.Location = new Point(10,10); xo.Width = 50; xo.Parent = this; TextBox to = new TextBox(); to.Parent = this; to.Location = new Point(90,10); to.Width = 600; to.Multiline = false; string Var1 = to.Text; Label x1 = new Label(); x1.Text = " ISBN : "; x1.Width = 50; x1.Location = new Point(10,50); x1.Parent = this; TextBox t1 = new TextBox(); t1.Parent = this; t1.Location = new Point(91,43); t1.Width = 600; t1.Multiline = false; string Var2 = t1.Text; Label x2 = new Label(); x2.Text = "Key Words :"; x2.Width = 80; x2.Parent = this; x2.Location = new Point(10,90); TextBox t2 = new TextBox(); t2.Parent = this; t2.Location = new Point(91,83); t2.Width = 600; t2.Multiline = false; string Var3 = t2.Text; Button bo = new Button(); Button b1 = new Button(); bo.Parent = this; b1.Parent = this; bo.Location = new Point(520,350); bo.Text = "Save"; bo.Height = 100; bo.Width = 100; Controls.Add(bo); b1.Location = new Point(630,350); b1.Text = "Close"; b1.Size = new Size(100,100); Controls.Add(b1); bo.Click += new EventHandler(onsave); b1.Click += new EventHandler(onExit); } void onsave(Object Sender,EventArgs e) { FileStream fs = new FileStream("test.txt",FileMode.OpenOrCreate,FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.WriteLine(to.Text); sw.WriteLine(t1.Text); sw.WriteLine(t2.Text); sw.Close(); } void onExit(Object Sender,EventArgs e) { Close(); } public static void Main() { Application.Run(new Mfury()); } } [\code]

        A Offline
        A Offline
        Afzaal Ahmad Zeeshan
        wrote on last edited by
        #3

        An easy idea would be, "you need to create a variable with that name, or you need to see if variable name has any typos". Secondly, as already mentioned. [code][\code] is supported on some websites, such as Quora. On CodeProject, you have to embed your code inside <pre> tags, or you can try out using the new Markdown[^] on CodeProject.

        The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

        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