namespace Patient_Information_System
{
public partial class Doctors : Form
{
public Doctors()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Main f2 = new Main();
f2.ShowDialog();
}
}
}
I get the error there.
Here is my main code.
namespace Patient_Information_System
{
public partial class Main : Form
{
public Main(string UserName)
{
InitializeComponent();
label11.Text = UserName;
toolStripStatusLabel2.Text = UserName;
timer1.Start();
load_usertbl();
}
I cant seem to fix it :/ Ive tried placing the username string outside the main part.
Loading

Anupam SinghRank #643 · 3.7K reputationPosted May 27, 2014, 9:42 AM EDT
you are making mistake here
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Main f2 = new Main(); //pass string as an argument in Main.
f2.ShowDialog();
}
Celine Ilano4 reputationPosted May 27, 2014, 7:28 PM EDT
Ranjit PowarRank #553 · 4.4K reputationPosted May 27, 2014, 8:21 PM EDT
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Main f2 = new Main("UserName");
f2.ShowDialog();
}
Anupam SinghRank #643 · 3.7K reputationPosted May 27, 2014, 8:40 PM EDT
public partial class Main : Form
{
public Main(string UserName)
{
InitializeComponent();
label11.Text = UserName;
toolStripStatusLabel2.Text = UserName;
timer1.Start();
load_usertbl();
}
}
Main method here is a constructor so you have to specify string type argument while creating instance.
Call it like :
Main obj=new Main("string_type");
I would suggest you ,dont create method with name Main() because it has different meaning in C#
Jignesh TrivediRank #16 · 50.3K reputationPosted May 27, 2014, 9:05 PM EDT
Agree with all above answer.
you can also create parameter less constructor or default constructor for main class like
public partial class Main : Form
{
public Main()
{
}
public Main(string UserName)
{
InitializeComponent();
label11.Text = UserName;
toolStripStatusLabel2.Text = UserName;
timer1.Start();
load_usertbl();
}
}
but this is depending upon your requirement.
hope this will help you.