The name does not exist in the current context
-
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]
-
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]
-
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]
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 !~