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;
}
else
{
MessageBox.Show(this, "Login not work", "",
MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void CancelButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
the main 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;
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)
{
}
}
}
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
and this is the error message
///////////////////////////////////////////
Error 1 The type or namespace name 'MainForm' could not be found (are
you missing a using directive or an assembly reference?) E:\Projects\C#
\Archive System\Archive System\Login.cs 18 28 Archive System
Error 2 The type or namespace name 'MainForm' could not be found (are
you missing a using directive or an assembly reference?) E:\Projects\C#
\Archive System\Archive System\Login.cs 20 22 Archive System
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
thank you for your help
Bes
Salim
On May 14, 3:55 am, Benj Nunez <[email protected]> wrote:
> You're welcome. :-)
>
> On May 13, 5:03 pm, sahm <[email protected]> wrote:
>
> > Hi Benj Nunez
>
> > thank you for your help
>
> > Salim
>
> > On May 5, 1:02 pm, Benj Nunez <[email protected]> wrote:
>
> > > Here's how:
>
> > > To begin with, let's assume you already have Form1 which has the
> > > menustrip. Make sure
> > > the modifier of your menustrip is set to public. We will construct
> > > Form2 (the childform):
>
> > > 1) Create a Newform(the childform)
> > > 2) declare a Form1 variable in your childformlike:
>
> > > private static new Form1 ParentForm = null;
>
> > > 3) define a second constructor, with Form1 as a parameter, like:
>
> > > public Form2(Form1 AParent): this()
> > > {
> > > ParentForm = AParent;
> > > }
>
> > > 4) drag a button in your childform.
> > > 5) double click your button and type this:
>
> > > private void btnEnable_Click(object sender, EventArgs e)
> > > {
> > > ParentForm.menuStrip1.Enabled = !
> > > ParentForm.menuStrip1.Enabled;
> > > }
>
> > > Now go back to your Form1 class to instantiate Form2. In this example,
> > > put
> > > a button in Form1. Double-click the button in Form1 and add this code:
>
> > > Form2 form2 = new Form2(this);
> > > form2.ShowDialog();
>
> > > Pass "this" to Form2. "this" refers to the Form1 instance. It allows
> > > you
> > > to access any controls in Form2. Provided that the controls in Form1
> > > have
> > > their modifiers set to public.
>
> > > Hope this helps.
>
> > > Benj
>
> > > On May 3, 9:31 pm, sahm <[email protected]> wrote:
>
> > > > Hi every one
> > > > How to can IenableordisableMenuStripin ParentFormfrom chiliad
> > > >form
> > > > Best
> > > > Salim