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(frmStrikeTournament));
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_Click);
//
// 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.CenterParent;
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) said:
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 said:
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