I am trying to pass a value from a texbox in Form1 to a textbox in Form2
using properties in VS2005 but it doesn't work; please help (project is
attached).
Code for Game Class:
using System;
using System.Collections.Generic;
using System.Text;
namespace MyProject
{
class Game
{
private string strName;
public string Name
{
get
{
return strName;
}
set
{
strName = value;
}
}
private string strMfg;
public string Mfg
{
get
{
return strMfg;
}
set
{
strMfg = value;
}
}
public Game()
{ }
public Game(string strName, string Mfg)
{
this.Name = strName;
this.Mfg = strMfg;
}
}
}
Code for Form1:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyProject
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Game clssGame = new Game();
clssGame.Name = txtName.Text;
clssGame.Mfg = txtMfg.Text;
Form2 frm = new Form2();
frm.ShowDialog();
}
}
}
Code for Form2:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyProject
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void Form2_Load(object sender, EventArgs e)
{
Game clssGame = new Game();
txtName.Text = clssGame.Name;
txtMfg.Text = clssGame.Mfg;
}
}
}