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
Jignesh TrivediPosted May 28, 2014, 1:05 AM
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.
Anupam SinghPosted May 28, 2014, 12:40 AM
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#
Ranjit PowarPosted May 28, 2014, 12:21 AM
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
Main f2 = new Main("UserName");
f2.ShowDialog();
}
Celine IlanoPosted May 27, 2014, 11:28 PM
Anupam SinghPosted May 27, 2014, 1:42 PM
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();
}