Hi,
I am new to C# and Forms/GUIs.
Basically I am trying to pass a value in a textBox to my programs program.cs file where I can apply my programs logic, but I'm stuck with how to do this.
To get started all I am making is a form which takes two variables, and I want to add those variables together and display the sum in a third text box.
I am stuck though with getting the value entered by the user into my program.cs file where I can use it/add the two values together.
My skeleton app is as follows:
The GUI:
SCREEN SHOT
Form1.cs :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//get the value from the textBox1 and put it into the variable a in the class/object Program.a
Application.Form1.a = this.textBox1.Text;//???????
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace MyApp
{
public class Program
{
public string a = "";
public string b = "";
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
On line 22 of Form1.cs I am trying to pass the value in the textbox to the variable 'a', which is part of the class Program. This is not working though, the compiler reports:
error CS0117: 'MyApp.Program' does not contain a definition for 'Form1'
Been stuck for ages trying to figure this out now. I'm using Visual Studio 2008 on Windows & 64 bit.
Could anyone tell me what I am doing wrong? I just want to pass the values entered by the user over to the file Program.cs where I can apply my programs logic, but despite trying to figure it out, I'm stuck.