By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,110 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Enable menuitem in parent form from mdichild

P: n/a
I'm trying to enable a menuitem in the parent form from a mdichild. Rather
than making the menuitems public, I'd go for a public method in the parent
form to do the change, but when I call the method from the mdichild, I get
this error:

C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frmLogin'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Hi Claus,
With the info you gave us it is really hard to tell.
What is 'test'?
Are the MDI container and MDI child in the same assembly? If not did you add
a reference to the container's assembly in the child project?
Did you use using statements? And so on. It is best if you perepate some
simple sample code that demonstrates the problem.

--

Stoitcho Goutsev (100) [C# MVP]
"Claus Holm" <Claus Ho**@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
I'm trying to enable a menuitem in the parent form from a mdichild. Rather
than making the menuitems public, I'd go for a public method in the parent
form to do the change, but when I call the method from the mdichild, I get
this error:

C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frmLogin'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm

Nov 16 '05 #2

P: n/a
Sorry about that, test was the function/sub (I'm coming from VB6), but here's
some more info:

Both forms are within the same namespace. In the parent form I've got

public void EnableMenuOnLogin()
{
mnuSystemSelectSystem.Enabled = true;
}

and in the mdichild, I've got

private void btnLogin_Click(object sender, System.EventArgs e)
{
EnableMenuOnLogin();
}

Thanks once again,
Claus

"Stoitcho Goutsev (100) [C# MVP]" wrote:
Hi Claus,
With the info you gave us it is really hard to tell.
What is 'test'?
Are the MDI container and MDI child in the same assembly? If not did you add
a reference to the container's assembly in the child project?
Did you use using statements? And so on. It is best if you perepate some
simple sample code that demonstrates the problem.

--

Stoitcho Goutsev (100) [C# MVP]
"Claus Holm" <Claus Ho**@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
I'm trying to enable a menuitem in the parent form from a mdichild. Rather
than making the menuitems public, I'd go for a public method in the parent
form to do the change, but when I call the method from the mdichild, I get
this error:

C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frmLogin'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm


Nov 16 '05 #3

P: n/a
Some more code from the 2 forms:

frmStrikeTournament:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace StrikeTournament
{
public class frmStrikeTournament : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mnuMain;
private System.Windows.Forms.MenuItem mnuSystem;
private System.Windows.Forms.MenuItem mnuSystemExit;
private System.Windows.Forms.MenuItem mnuSystemSelectSystem;
private System.Windows.Forms.MenuItem mnuSystemSeperator1;
private System.Windows.Forms.MenuItem mnuSystemAdminLogin;
private System.Windows.Forms.MenuItem mnuSystemSetup;
private System.Windows.Forms.MenuItem mnuSystemSeperator2;
private System.Windows.Forms.MenuItem mnuHelp;
private System.Windows.Forms.MenuItem mnuHelpHelp;
private System.Windows.Forms.MenuItem mnuHelpAbout;
private System.Windows.Forms.MenuItem mnuSystemSetupTournament;
private System.Windows.Forms.MenuItem mnuSystemSetupCategory;
private System.Windows.Forms.MenuItem mnuSystemSetupRow;

private System.ComponentModel.Container components = null;

public frmStrikeTournament()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(frmStrikeT ournament));
this.mnuMain = new System.Windows.Forms.MainMenu();
this.mnuSystem = new System.Windows.Forms.MenuItem();
this.mnuSystemSelectSystem = new System.Windows.Forms.MenuItem();
this.mnuSystemSeperator1 = new System.Windows.Forms.MenuItem();
this.mnuSystemAdminLogin = new System.Windows.Forms.MenuItem();
this.mnuSystemSetup = new System.Windows.Forms.MenuItem();
this.mnuSystemSetupTournament = new System.Windows.Forms.MenuItem();
this.mnuSystemSetupCategory = new System.Windows.Forms.MenuItem();
this.mnuSystemSetupRow = new System.Windows.Forms.MenuItem();
this.mnuSystemSeperator2 = new System.Windows.Forms.MenuItem();
this.mnuSystemExit = new System.Windows.Forms.MenuItem();
this.mnuHelp = new System.Windows.Forms.MenuItem();
this.mnuHelpHelp = new System.Windows.Forms.MenuItem();
this.mnuHelpAbout = new System.Windows.Forms.MenuItem();
//
// mnuMain
//
this.mnuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuSystem,
this.mnuHelp});
//
// mnuSystem
//
this.mnuSystem.Index = 0;
this.mnuSystem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuSystemSelectSystem,
this.mnuSystemSeperator1,
this.mnuSystemAdminLogin,
this.mnuSystemSetup,
this.mnuSystemSeperator2,
this.mnuSystemExit});
this.mnuSystem.Text = "&System";
//
// mnuSystemSelectSystem
//
this.mnuSystemSelectSystem.Enabled = false;
this.mnuSystemSelectSystem.Index = 0;
this.mnuSystemSelectSystem.Text = "&Vælg system";
this.mnuSystemSelectSystem.Click += new
System.EventHandler(this.mnuSystemSelectSystem_Cli ck);
//
// mnuSystemSeperator1
//
this.mnuSystemSeperator1.Index = 1;
this.mnuSystemSeperator1.Text = "-";
//
// mnuSystemAdminLogin
//
this.mnuSystemAdminLogin.Index = 2;
this.mnuSystemAdminLogin.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.mnuSystemAdminLogin.Text = "Administrator &login";
this.mnuSystemAdminLogin.Click += new
System.EventHandler(this.mnuSystemAdminLogin_Click );
//
// mnuSystemSetup
//
this.mnuSystemSetup.Enabled = false;
this.mnuSystemSetup.Index = 3;
this.mnuSystemSetup.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.mnuSystemSetupTournament,
this.mnuSystemSetupCategory,
this.mnuSystemSetupRow});
this.mnuSystemSetup.Text = "&Opsætning af stævne";
//
// mnuSystemSetupTournament
//
this.mnuSystemSetupTournament.Index = 0;
this.mnuSystemSetupTournament.Text = "&Stævne";
//
// mnuSystemSetupCategory
//
this.mnuSystemSetupCategory.Index = 1;
this.mnuSystemSetupCategory.Text = "&Kategori";
//
// mnuSystemSetupRow
//
this.mnuSystemSetupRow.Index = 2;
this.mnuSystemSetupRow.Text = "&Række";
//
// mnuSystemSeperator2
//
this.mnuSystemSeperator2.Index = 4;
this.mnuSystemSeperator2.Text = "-";
//
// mnuSystemExit
//
this.mnuSystemExit.Index = 5;
this.mnuSystemExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.mnuSystemExit.Text = "&Afslut";
this.mnuSystemExit.Click += new
System.EventHandler(this.mnuSystemExit_Click);
//
// mnuHelp
//
this.mnuHelp.Index = 1;
this.mnuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuHelpHelp,
this.mnuHelpAbout});
this.mnuHelp.Text = "&Hjælp";
//
// mnuHelpHelp
//
this.mnuHelpHelp.Index = 0;
this.mnuHelpHelp.Shortcut = System.Windows.Forms.Shortcut.F1;
this.mnuHelpHelp.Text = "Strike Tournament .NET hjælp";
//
// mnuHelpAbout
//
this.mnuHelpAbout.Index = 1;
this.mnuHelpAbout.Text = "&Om Strike Tournament .NET";
//
// frmStrikeTournament
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(736, 449);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.IsMdiContainer = true;
this.Menu = this.mnuMain;
this.Name = "frmStrikeTournament";
this.Text = "Strike Tournament .NET";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.frmStrikeTournament_Load) ;

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmStrikeTournament());
}

private void mnuSystemExit_Click(object sender, System.EventArgs e)
{
this.Dispose();
}

private void frmStrikeTournament_Load(object sender, System.EventArgs e)
{
// Calling from here works
fine...
EnableMenuOnLogin();
}

private void mnuSystemAdminLogin_Click(object sender, System.EventArgs e)
{
frmLogin newMDIChild = new frmLogin();
newMDIChild.MdiParent = this;
newMDIChild.Show();
}

private void mnuSystemSelectSystem_Click(object sender, System.EventArgs e)
{

}

public void EnableMenuOnLogin()
{
// public, but doesn't seem
to be visible for the other form
this.mnuSystemSelectSystem.Enabled = true;
}
}
}
frmLogin:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace StrikeTournament
{
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox gbxLogin;
private System.Windows.Forms.Label lblUserId;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.TextBox txtUserId;
private System.Windows.Forms.TextBox txtPassword;
private System.ComponentModel.Container components = null;

public frmLogin()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(frmLogin)) ;
this.gbxLogin = new System.Windows.Forms.GroupBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.txtUserId = new System.Windows.Forms.TextBox();
this.btnLogin = new System.Windows.Forms.Button();
this.lblPassword = new System.Windows.Forms.Label();
this.lblUserId = new System.Windows.Forms.Label();
this.gbxLogin.SuspendLayout();
this.SuspendLayout();
//
// gbxLogin
//
this.gbxLogin.Controls.Add(this.txtPassword);
this.gbxLogin.Controls.Add(this.txtUserId);
this.gbxLogin.Controls.Add(this.btnLogin);
this.gbxLogin.Controls.Add(this.lblPassword);
this.gbxLogin.Controls.Add(this.lblUserId);
this.gbxLogin.Location = new System.Drawing.Point(8, 8);
this.gbxLogin.Name = "gbxLogin";
this.gbxLogin.Size = new System.Drawing.Size(288, 96);
this.gbxLogin.TabIndex = 0;
this.gbxLogin.TabStop = false;
this.gbxLogin.Text = "Administrator login";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(144, 40);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(136, 20);
this.txtPassword.TabIndex = 4;
this.txtPassword.Text = "";
//
// txtUserId
//
this.txtUserId.Location = new System.Drawing.Point(144, 16);
this.txtUserId.Name = "txtUserId";
this.txtUserId.Size = new System.Drawing.Size(136, 20);
this.txtUserId.TabIndex = 3;
this.txtUserId.Text = "";
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(208, 64);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(72, 24);
this.btnLogin.TabIndex = 2;
this.btnLogin.Text = "&Login";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(8, 44);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(136, 16);
this.lblPassword.TabIndex = 1;
this.lblPassword.Text = "Password:";
//
// lblUserId
//
this.lblUserId.Location = new System.Drawing.Point(8, 20);
this.lblUserId.Name = "lblUserId";
this.lblUserId.Size = new System.Drawing.Size(136, 16);
this.lblUserId.TabIndex = 0;
this.lblUserId.Text = "&Bruger Id:";
//
// frmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(304, 310);
this.Controls.Add(this.gbxLogin);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmLogin";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParen t;
this.Text = "Administrator login";
this.Load += new System.EventHandler(this.frmLogin_Load);
this.gbxLogin.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

private void frmLogin_Load(object sender, System.EventArgs e)
{

}

private void btnLogin_Click(object sender, System.EventArgs e)
{
// Call from here errors,
seems to be looking locally for the method, not the public one in the other
form
EnableMenuOnLogin();
}
}
}
"Stoitcho Goutsev (100) [C# MVP]" wrote:
Hi Claus,
With the info you gave us it is really hard to tell.
What is 'test'?
Are the MDI container and MDI child in the same assembly? If not did you add
a reference to the container's assembly in the child project?
Did you use using statements? And so on. It is best if you perepate some
simple sample code that demonstrates the problem.

--

Stoitcho Goutsev (100) [C# MVP]
"Claus Holm" <Claus Ho**@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
I'm trying to enable a menuitem in the parent form from a mdichild. Rather
than making the menuitems public, I'd go for a public method in the parent
form to do the change, but when I call the method from the mdichild, I get
this error:

C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frmLogin'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm


Nov 16 '05 #4

P: n/a
Hi Claus,

I guess your concerns are about the compiler error that you in that method

private void btnLogin_Click(object sender, System.EventArgs e)
{
// Call from here errors,
seems to be looking locally for the method, not the public one in the other
form
EnableMenuOnLogin();
}

The compiler is right. There is no EnableMenuOnLogin method declared in the
frmLogin class

This method is declared in the MDI container class (frmStrikeTournament
class). To call this method you need a reference to the MDI container object

((frmStrikeTournament)this.MdiParent).EnableMenuOn Login();

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Claus Holm" <Cl*******@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
Some more code from the 2 forms:

frmStrikeTournament:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace StrikeTournament
{
public class frmStrikeTournament : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mnuMain;
private System.Windows.Forms.MenuItem mnuSystem;
private System.Windows.Forms.MenuItem mnuSystemExit;
private System.Windows.Forms.MenuItem mnuSystemSelectSystem;
private System.Windows.Forms.MenuItem mnuSystemSeperator1;
private System.Windows.Forms.MenuItem mnuSystemAdminLogin;
private System.Windows.Forms.MenuItem mnuSystemSetup;
private System.Windows.Forms.MenuItem mnuSystemSeperator2;
private System.Windows.Forms.MenuItem mnuHelp;
private System.Windows.Forms.MenuItem mnuHelpHelp;
private System.Windows.Forms.MenuItem mnuHelpAbout;
private System.Windows.Forms.MenuItem mnuSystemSetupTournament;
private System.Windows.Forms.MenuItem mnuSystemSetupCategory;
private System.Windows.Forms.MenuItem mnuSystemSetupRow;

private System.ComponentModel.Container components = null;

public frmStrikeTournament()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(frmStrikeT ournament));
this.mnuMain = new System.Windows.Forms.MainMenu();
this.mnuSystem = new System.Windows.Forms.MenuItem();
this.mnuSystemSelectSystem = new System.Windows.Forms.MenuItem();
this.mnuSystemSeperator1 = new System.Windows.Forms.MenuItem();
this.mnuSystemAdminLogin = new System.Windows.Forms.MenuItem();
this.mnuSystemSetup = new System.Windows.Forms.MenuItem();
this.mnuSystemSetupTournament = new System.Windows.Forms.MenuItem();
this.mnuSystemSetupCategory = new System.Windows.Forms.MenuItem();
this.mnuSystemSetupRow = new System.Windows.Forms.MenuItem();
this.mnuSystemSeperator2 = new System.Windows.Forms.MenuItem();
this.mnuSystemExit = new System.Windows.Forms.MenuItem();
this.mnuHelp = new System.Windows.Forms.MenuItem();
this.mnuHelpHelp = new System.Windows.Forms.MenuItem();
this.mnuHelpAbout = new System.Windows.Forms.MenuItem();
//
// mnuMain
//
this.mnuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuSystem,
this.mnuHelp});
//
// mnuSystem
//
this.mnuSystem.Index = 0;
this.mnuSystem.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuSystemSelectSystem,
this.mnuSystemSeperator1,
this.mnuSystemAdminLogin,
this.mnuSystemSetup,
this.mnuSystemSeperator2,
this.mnuSystemExit});
this.mnuSystem.Text = "&System";
//
// mnuSystemSelectSystem
//
this.mnuSystemSelectSystem.Enabled = false;
this.mnuSystemSelectSystem.Index = 0;
this.mnuSystemSelectSystem.Text = "&Vlg system";
this.mnuSystemSelectSystem.Click += new
System.EventHandler(this.mnuSystemSelectSystem_Cli ck);
//
// mnuSystemSeperator1
//
this.mnuSystemSeperator1.Index = 1;
this.mnuSystemSeperator1.Text = "-";
//
// mnuSystemAdminLogin
//
this.mnuSystemAdminLogin.Index = 2;
this.mnuSystemAdminLogin.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.mnuSystemAdminLogin.Text = "Administrator &login";
this.mnuSystemAdminLogin.Click += new
System.EventHandler(this.mnuSystemAdminLogin_Click );
//
// mnuSystemSetup
//
this.mnuSystemSetup.Enabled = false;
this.mnuSystemSetup.Index = 3;
this.mnuSystemSetup.MenuItems.AddRange(new
System.Windows.Forms.MenuItem[] {
this.mnuSystemSetupTournament,
this.mnuSystemSetupCategory,
this.mnuSystemSetupRow});
this.mnuSystemSetup.Text = "&Opstning af stvne";
//
// mnuSystemSetupTournament
//
this.mnuSystemSetupTournament.Index = 0;
this.mnuSystemSetupTournament.Text = "&Stvne";
//
// mnuSystemSetupCategory
//
this.mnuSystemSetupCategory.Index = 1;
this.mnuSystemSetupCategory.Text = "&Kategori";
//
// mnuSystemSetupRow
//
this.mnuSystemSetupRow.Index = 2;
this.mnuSystemSetupRow.Text = "&Rkke";
//
// mnuSystemSeperator2
//
this.mnuSystemSeperator2.Index = 4;
this.mnuSystemSeperator2.Text = "-";
//
// mnuSystemExit
//
this.mnuSystemExit.Index = 5;
this.mnuSystemExit.Shortcut = System.Windows.Forms.Shortcut.CtrlX;
this.mnuSystemExit.Text = "&Afslut";
this.mnuSystemExit.Click += new
System.EventHandler(this.mnuSystemExit_Click);
//
// mnuHelp
//
this.mnuHelp.Index = 1;
this.mnuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.mnuHelpHelp,
this.mnuHelpAbout});
this.mnuHelp.Text = "&Hjlp";
//
// mnuHelpHelp
//
this.mnuHelpHelp.Index = 0;
this.mnuHelpHelp.Shortcut = System.Windows.Forms.Shortcut.F1;
this.mnuHelpHelp.Text = "Strike Tournament .NET hjlp";
//
// mnuHelpAbout
//
this.mnuHelpAbout.Index = 1;
this.mnuHelpAbout.Text = "&Om Strike Tournament .NET";
//
// frmStrikeTournament
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(736, 449);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.IsMdiContainer = true;
this.Menu = this.mnuMain;
this.Name = "frmStrikeTournament";
this.Text = "Strike Tournament .NET";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.frmStrikeTournament_Load) ;

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmStrikeTournament());
}

private void mnuSystemExit_Click(object sender, System.EventArgs e)
{
this.Dispose();
}

private void frmStrikeTournament_Load(object sender, System.EventArgs e)
{
// Calling from here works
fine...
EnableMenuOnLogin();
}

private void mnuSystemAdminLogin_Click(object sender, System.EventArgs e)
{
frmLogin newMDIChild = new frmLogin();
newMDIChild.MdiParent = this;
newMDIChild.Show();
}

private void mnuSystemSelectSystem_Click(object sender, System.EventArgs
e)
{

}

public void EnableMenuOnLogin()
{
// public, but doesn't seem
to be visible for the other form
this.mnuSystemSelectSystem.Enabled = true;
}
}
}
frmLogin:

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace StrikeTournament
{
public class frmLogin : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox gbxLogin;
private System.Windows.Forms.Label lblUserId;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.TextBox txtUserId;
private System.Windows.Forms.TextBox txtPassword;
private System.ComponentModel.Container components = null;

public frmLogin()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(frmLogin)) ;
this.gbxLogin = new System.Windows.Forms.GroupBox();
this.txtPassword = new System.Windows.Forms.TextBox();
this.txtUserId = new System.Windows.Forms.TextBox();
this.btnLogin = new System.Windows.Forms.Button();
this.lblPassword = new System.Windows.Forms.Label();
this.lblUserId = new System.Windows.Forms.Label();
this.gbxLogin.SuspendLayout();
this.SuspendLayout();
//
// gbxLogin
//
this.gbxLogin.Controls.Add(this.txtPassword);
this.gbxLogin.Controls.Add(this.txtUserId);
this.gbxLogin.Controls.Add(this.btnLogin);
this.gbxLogin.Controls.Add(this.lblPassword);
this.gbxLogin.Controls.Add(this.lblUserId);
this.gbxLogin.Location = new System.Drawing.Point(8, 8);
this.gbxLogin.Name = "gbxLogin";
this.gbxLogin.Size = new System.Drawing.Size(288, 96);
this.gbxLogin.TabIndex = 0;
this.gbxLogin.TabStop = false;
this.gbxLogin.Text = "Administrator login";
//
// txtPassword
//
this.txtPassword.Location = new System.Drawing.Point(144, 40);
this.txtPassword.Name = "txtPassword";
this.txtPassword.Size = new System.Drawing.Size(136, 20);
this.txtPassword.TabIndex = 4;
this.txtPassword.Text = "";
//
// txtUserId
//
this.txtUserId.Location = new System.Drawing.Point(144, 16);
this.txtUserId.Name = "txtUserId";
this.txtUserId.Size = new System.Drawing.Size(136, 20);
this.txtUserId.TabIndex = 3;
this.txtUserId.Text = "";
//
// btnLogin
//
this.btnLogin.Location = new System.Drawing.Point(208, 64);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(72, 24);
this.btnLogin.TabIndex = 2;
this.btnLogin.Text = "&Login";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// lblPassword
//
this.lblPassword.Location = new System.Drawing.Point(8, 44);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(136, 16);
this.lblPassword.TabIndex = 1;
this.lblPassword.Text = "Password:";
//
// lblUserId
//
this.lblUserId.Location = new System.Drawing.Point(8, 20);
this.lblUserId.Name = "lblUserId";
this.lblUserId.Size = new System.Drawing.Size(136, 16);
this.lblUserId.TabIndex = 0;
this.lblUserId.Text = "&Bruger Id:";
//
// frmLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(304, 310);
this.Controls.Add(this.gbxLogin);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "frmLogin";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParen t;
this.Text = "Administrator login";
this.Load += new System.EventHandler(this.frmLogin_Load);
this.gbxLogin.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

private void frmLogin_Load(object sender, System.EventArgs e)
{

}

private void btnLogin_Click(object sender, System.EventArgs e)
{
// Call from here errors,
seems to be looking locally for the method, not the public one in the
other
form
EnableMenuOnLogin();
}
}
}
"Stoitcho Goutsev (100) [C# MVP]" wrote:
Hi Claus,
With the info you gave us it is really hard to tell.
What is 'test'?
Are the MDI container and MDI child in the same assembly? If not did you
add
a reference to the container's assembly in the child project?
Did you use using statements? And so on. It is best if you perepate some
simple sample code that demonstrates the problem.

--

Stoitcho Goutsev (100) [C# MVP]
"Claus Holm" <Claus Ho**@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
> I'm trying to enable a menuitem in the parent form from a mdichild.
> Rather
> than making the menuitems public, I'd go for a public method in the
> parent
> form to do the change, but when I call the method from the mdichild, I
> get
> this error:
>
> C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69):
> The
> name 'test' does not exist in the class or namespace
> 'Tournament.frmLogin'
>
> frmLogin is the mdichild.
>
> What am I missing here?
>
> Thanks,
> Claus Holm


Nov 16 '05 #5

P: n/a
Thanks, it works. Coming from VB6 it seems strange, that when the method is
public and I'm in the same namespace, it's not accessible after all. Are
there other ways of handling things like this? - I'm thinking in the line of
the using statement?

Thanks once again,
Claus

seems to be looking locally for the method, not the public one in the other
form
EnableMenuOnLogin();
}

The compiler is right. There is no EnableMenuOnLogin method declared in the
frmLogin class

This method is declared in the MDI container class (frmStrikeTournament
class). To call this method you need a reference to the MDI container object

((frmStrikeTournament)this.MdiParent).EnableMenuOn Login();

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Nov 16 '05 #6

P: n/a
Hi Claus,

Thanks, it works. Coming from VB6 it seems strange, that when the method
is
public and I'm in the same namespace, it's not accessible after all.
I've no experiance with VB6 and I know that there is big time frustration
among VB6 programmers about the changes made in VB .NET, but I'm still
little bit surprised that VB can compile the code withiout the reference
(see my next answer).
Are there other ways of handling things like this? - I'm thinking in the
line of
the using statement?


No there is not. *using* is used to save some typing by skipping the
namesapce part of the type names or to give namespaces and types different
names thus, solving name clashes, but in your case you want to access public
instance so you have to give a reference to the object, which member you
call. What if there were two dsitinctive objects (instance of this type)? If
you don't use the reference how can you specify, which object's member you
want to call. How I said I have no experience with VB, but I'm surprise that
it can chew this code

--

Stoitcho Goutsev (100) [C# MVP]
Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.