I know I have been posting quite a few questions these few days....all I have found the solution to on my own after playing around more....i'll be sure to update thoses so I dont start spaming the forum with un-answered posts which I appoligise about for now.
Im having a little problem trying to get a variable passed between two forms. I have set a variable which is a string on form2 and need it shared, or passed, to form1. I have included my code for both my form1 and form2.
on compile, I keep getting the error:
Error 1 An object reference is required for the nonstatic field, method, or property 'Form1.cs'
HERE IS MY FORM1
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Jesup_Administrator
{
public partial class form1 : Form
{
public form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Form myForm = new form2();
myForm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = form2.Password;
}
}
}
HERE IS MY FORM2
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Jesup_Administrator
{
public partial class form2 : Form
{
public string Password = "";
public form2()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
button1.Enabled = !string.IsNullOrEmpty(textBox1.Text);
}
private void button1_Click(object sender, EventArgs e)
{
Password = textBox1.Text;
this.Close();
}
}
}
I know I should really be learning more before jumping into creating a GUI: I am learning form an O'reilly C# 2005 book, but I really would like some help at this point with this windows application, passing my string variable to form1.
Thanks a lot.