It means that either: 1) A class needs to be instantiated with "new", but was not done so.
or 2) A class has been instantiated BUT you assigned Nothing (VB) or null (C#) to it, and then you attempted to use the methods from it. Kindly look at the code again. Cheers! Benj On May 28, 5:04 pm, sahm <[email protected]> wrote: > Hi every one > > Good Day > > I still get this error > ///////////////////////////////////// > Object reference not set to an instance of an object > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > Best > > Salim > > On May 18, 4:28 am, CallMeLaNN <[email protected]> wrote: > > > I thought you want to use MDI for login form. > > > If so, you need to add log.MdiParent = this; here: > > > Login log = new Login(); > > log.MdiParent = this; > > log.Show(); > > > Note: to make your login visible, place the checkUser(); not in > > "public Main()" constructor but in Main_Load(). > > > The "Object reference not set to an instance of an object" is because > > of your > > ParentForm or this.MdiParent is null at here: > > > Main ParentForm = (Main)this.MdiParent; > > > and sure will throw the error when you use it: > > ParentForm.menuStrip1.Enabled = false; > > > On May 17, 2:10 pm, sahm <[email protected]> wrote: > > > > Hi every One > > > > Good Day > > > > I'm still having problem with this > > > I write the code like this > > > > //////////////////////////////////// > > > Login log = new Login(this); > > > log.ShowDialog(); > > > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > > this error is showing > > > /////////////////////////////////////// > > > Error 1 'Archive_System.Login' does not contain a constructor that > > > takes '1' arguments E:\Projects\C#\Archive System\Archive System > > > \MainForm.cs 68 25 Archive System > > > > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > > and if I writ is like this > > > ////////////////////////////// > > > Login log = new Login(); > > > log.ShowDialog(this); > > > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > > Run time error is showing after I Enter the user name and the password > > > /////////////////////////////////// > > > Object reference not set to an instance of an object > > > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > > and this is my code > > > > MainForm > > > ///////////////////////////////////// > > > 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; > > > using System.Management; > > > > namespace Archive_System > > > { > > > public partial class Main : Form > > > { > > > public Main() > > > { > > > try > > > { > > > InitializeComponent(); > > > this.WindowState = FormWindowState.Maximized; > > > this.FormBorderStyle = FormBorderStyle.FixedSingle; > > > this.Closing += new CancelEventHandler(Form_Closing); > > > > this.menuStrip1.Enabled = false; > > > //this.Enabled = false; > > > checkUser(); > > > } > > > catch (Exception exp) > > > { > > > string ms = exp.Message; > > > MessageBox.Show(this, ms, "System Error", > > > MessageBoxButtons.OK, MessageBoxIcon.Error); > > > > } > > > } > > > > System.Data.SqlClient.SqlConnection con; > > > > private void userToolStripMenuItem_Click(object sender, > > > EventArgs e) > > > { > > > try > > > { > > > createUser cu = new createUser(); > > > cu.MdiParent = this; > > > cu.Show(); > > > > } > > > catch (Exception exp) > > > { > > > string ms = exp.Message; > > > MessageBox.Show(this, ms, "System Error", > > > MessageBoxButtons.OK, MessageBoxIcon.Error); > > > } > > > } > > > > private void aboutToolStripMenuItem_Click(object sender, > > > EventArgs e) > > > { > > > About ab = new About(); > > > ab.MdiParent = this; > > > ab.Show(); > > > } > > > /*public void setPreviousForm(frmMain mainFrm) > > > { > > > prevForm = mainForm; > > > }*/ > > > public void checkUser() > > > { > > > Login log = new Login(); > > > //log.setPreviousForm(this); > > > log.ShowDialog(this); > > > > } > > > > private void Main_Load(object sender, EventArgs e) > > > { > > > con = new System.Data.SqlClient.SqlConnection(); > > > con.ConnectionString = "Data Source=mr-x\ > > > \SQLExpress2008;Initial Catalog=archive;Integrated Security=True"; > > > con.Open(); > > > > } > > > > public void Form_Closing(object sender, CancelEventArgs cArgs) > > > { > > > con.Close(); > > > > } > > > > private void menuStrip1_ItemClicked(object sender, > > > ToolStripItemClickedEventArgs e) > > > { > > > > } > > > > }} > > > > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > > Login > > > ///////////////////////////////////// > > > 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 Archive_System > > > { > > > public partial class Login : Form > > > { > > > public Login() > > > { > > > InitializeComponent(); > > > } > > > //private static new MainForm ParentForm = null; > > > > /*public Login(MainForm APrent):this() > > > { > > > Main ParentForm =(Main) this.MdiParent; > > > }*/ > > > > private void OKbutton_Click(object sender, EventArgs e) > > > { > > > string un = userNametextBox.Text; > > > string ps = PasswardMaskedTextBox.Text; > > > > if (un == "sahm" || ps == "java") > > > { > > > MessageBox.Show(this, "Login Work", "", > > > MessageBoxButtons.OK, MessageBoxIcon.Information); > > > //ParentForm.menuStrip1.Enabled = ! > > > ParentForm.menuStrip1.Enabled; > > > Main ParentForm = (Main)this.MdiParent; > > > ParentForm.menuStrip1.Enabled = false; > > > > } > > > else > > > { > > > MessageBox.Show(this, "Login not work", "", > > > MessageBoxButtons.OK, MessageBoxIcon.Information); > > > } > > > > } > > > > private void CancelButton_Click(object sender, EventArgs e) > > > { > > > this.Close(); > > > } > > > > }} > > > > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ > > > > Thank every one > > > > Best > > > > Salim > > > > On May 16, 10:45 am, sahm <[email protected]> wrote: > > > > > Hi CallMeLann > > > > > Thank for your help I'll try this > > > > > Best > > > > Salim > > > > > On May 15, 11:23 am, CallMeLaNN <[email protected]> wrote: > > > > > > Because you use: > > > > > > Login log = new Login(); > > > > > > In MainForm but you declare: > > > > > > public Login(MainForm APrent):this() > > > > > > Which LoginForm need APrent value that is MainForm. > > > > > To solve change to this: > > > > > > Login log = new Login(this); > > > > > > But, I recommend u to use MdiParent instead. > > > > > > 1. Remove the "private static new MainForm ParentForm = null;" no need > > > > > to use this. > > > > > 2. login constructor: let it default constructor (no parameter): > > > > > "public Login()" > > > > > 3. To disable the menu use like this: (Im not sure your main form type > > > > > is Main or MainForm based on your code, I assume Main) > > > > > > Main ParentForm = (Main) this.MdiParent > > > > > ParentForm.menuStrip1.Enabled = False > > > > > > dont use ! for toggle it, it can be wrong toggle, instead, assign true > > > > > or false if you sure. > > > > > > On May 14, 4:01 pm, sahm <[email protected]> wrote: > > > > > > > Hi Benj Nunez > > > > > > > Good Day > > > > > > > I try to do that but some error show up > > > > > > and this is my code > > > > > > > the child form > > > > > > //////////////////////////////////////////////////// > > > > > > > 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 Archive_System > > > > > > { > > > > > > public partial class Login : Form > > > > > > { > > > > > > public Login() > > > > > > { > > > > > > InitializeComponent(); > > > > > > } > > > > > > private static new MainForm ParentForm = null; > > > > > > > public Login(MainForm APrent):this() > > > > > > { > > > > > > ParentForm = APrent; > > > > > > } > > > > > > > private void OKbutton_Click(object sender, EventArgs e) > > > > > > { > > > > > > string un = userNametextBox.Text; > > > > > > string ps = PasswardMaskedTextBox.Text; > > > > > > > if (un == "sahm" || ps == "java") > > > > > > { > > > > > > MessageBox.Show(this, "Login Work", "", > > > > > > MessageBoxButtons.OK, MessageBoxIcon.Information); > > > > > > ParentForm.menuStrip1.Enabled = ! > > > > > > ParentForm.menuStrip1.Enabled; > > > > > > > } > > > > > > > > ... > > read more »
