473,734 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Enable menuitem in parent form from mdichild

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\V isual Studio Projects\Tourna ment\Forms\frmL ogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frm Login'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm
Nov 16 '05 #1
6 6222
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**@discussion s.microsoft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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\V isual Studio Projects\Tourna ment\Forms\frmL ogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frm Login'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm

Nov 16 '05 #2
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 EnableMenuOnLog in()
{
mnuSystemSelect System.Enabled = true;
}

and in the mdichild, I've got

private void btnLogin_Click( object sender, System.EventArg s e)
{
EnableMenuOnLog in();
}

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**@discussion s.microsoft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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\V isual Studio Projects\Tourna ment\Forms\frmL ogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frm Login'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm


Nov 16 '05 #3
Some more code from the 2 forms:

frmStrikeTourna ment:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace StrikeTournamen t
{
public class frmStrikeTourna ment : 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 mnuSystemSelect System;
private System.Windows. Forms.MenuItem mnuSystemSepera tor1;
private System.Windows. Forms.MenuItem mnuSystemAdminL ogin;
private System.Windows. Forms.MenuItem mnuSystemSetup;
private System.Windows. Forms.MenuItem mnuSystemSepera tor2;
private System.Windows. Forms.MenuItem mnuHelp;
private System.Windows. Forms.MenuItem mnuHelpHelp;
private System.Windows. Forms.MenuItem mnuHelpAbout;
private System.Windows. Forms.MenuItem mnuSystemSetupT ournament;
private System.Windows. Forms.MenuItem mnuSystemSetupC ategory;
private System.Windows. Forms.MenuItem mnuSystemSetupR ow;

private System.Componen tModel.Containe r components = null;

public frmStrikeTourna ment()
{
InitializeCompo nent();
}

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

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
System.Resource s.ResourceManag er resources = new
System.Resource s.ResourceManag er(typeof(frmSt rikeTournament) );
this.mnuMain = new System.Windows. Forms.MainMenu( );
this.mnuSystem = new System.Windows. Forms.MenuItem( );
this.mnuSystemS electSystem = new System.Windows. Forms.MenuItem( );
this.mnuSystemS eperator1 = new System.Windows. Forms.MenuItem( );
this.mnuSystemA dminLogin = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etup = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etupTournament = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etupCategory = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etupRow = new System.Windows. Forms.MenuItem( );
this.mnuSystemS eperator2 = new System.Windows. Forms.MenuItem( );
this.mnuSystemE xit = new System.Windows. Forms.MenuItem( );
this.mnuHelp = new System.Windows. Forms.MenuItem( );
this.mnuHelpHel p = new System.Windows. Forms.MenuItem( );
this.mnuHelpAbo ut = new System.Windows. Forms.MenuItem( );
//
// mnuMain
//
this.mnuMain.Me nuItems.AddRang e(new System.Windows. Forms.MenuItem[] {
this.mnuSystem,
this.mnuHelp});
//
// mnuSystem
//
this.mnuSystem. Index = 0;
this.mnuSystem. MenuItems.AddRa nge(new System.Windows. Forms.MenuItem[] {
this.mnuSystemS electSystem,
this.mnuSystemS eperator1,
this.mnuSystemA dminLogin,
this.mnuSystemS etup,
this.mnuSystemS eperator2,
this.mnuSystemE xit});
this.mnuSystem. Text = "&System";
//
// mnuSystemSelect System
//
this.mnuSystemS electSystem.Ena bled = false;
this.mnuSystemS electSystem.Ind ex = 0;
this.mnuSystemS electSystem.Tex t = "&Vælg system";
this.mnuSystemS electSystem.Cli ck += new
System.EventHan dler(this.mnuSy stemSelectSyste m_Click);
//
// mnuSystemSepera tor1
//
this.mnuSystemS eperator1.Index = 1;
this.mnuSystemS eperator1.Text = "-";
//
// mnuSystemAdminL ogin
//
this.mnuSystemA dminLogin.Index = 2;
this.mnuSystemA dminLogin.Short cut = System.Windows. Forms.Shortcut. CtrlA;
this.mnuSystemA dminLogin.Text = "Administra tor &login";
this.mnuSystemA dminLogin.Click += new
System.EventHan dler(this.mnuSy stemAdminLogin_ Click);
//
// mnuSystemSetup
//
this.mnuSystemS etup.Enabled = false;
this.mnuSystemS etup.Index = 3;
this.mnuSystemS etup.MenuItems. AddRange(new
System.Windows. Forms.MenuItem[] {
this.mnuSystemS etupTournament,
this.mnuSystemS etupCategory,
this.mnuSystemS etupRow});
this.mnuSystemS etup.Text = "&Opsætnin g af stævne";
//
// mnuSystemSetupT ournament
//
this.mnuSystemS etupTournament. Index = 0;
this.mnuSystemS etupTournament. Text = "&Stævne";
//
// mnuSystemSetupC ategory
//
this.mnuSystemS etupCategory.In dex = 1;
this.mnuSystemS etupCategory.Te xt = "&Kategori" ;
//
// mnuSystemSetupR ow
//
this.mnuSystemS etupRow.Index = 2;
this.mnuSystemS etupRow.Text = "&Række";
//
// mnuSystemSepera tor2
//
this.mnuSystemS eperator2.Index = 4;
this.mnuSystemS eperator2.Text = "-";
//
// mnuSystemExit
//
this.mnuSystemE xit.Index = 5;
this.mnuSystemE xit.Shortcut = System.Windows. Forms.Shortcut. CtrlX;
this.mnuSystemE xit.Text = "&Afslut";
this.mnuSystemE xit.Click += new
System.EventHan dler(this.mnuSy stemExit_Click) ;
//
// mnuHelp
//
this.mnuHelp.In dex = 1;
this.mnuHelp.Me nuItems.AddRang e(new System.Windows. Forms.MenuItem[] {
this.mnuHelpHel p,
this.mnuHelpAbo ut});
this.mnuHelp.Te xt = "&Hjælp";
//
// mnuHelpHelp
//
this.mnuHelpHel p.Index = 0;
this.mnuHelpHel p.Shortcut = System.Windows. Forms.Shortcut. F1;
this.mnuHelpHel p.Text = "Strike Tournament .NET hjælp";
//
// mnuHelpAbout
//
this.mnuHelpAbo ut.Index = 1;
this.mnuHelpAbo ut.Text = "&Om Strike Tournament .NET";
//
// frmStrikeTourna ment
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(736, 449);
this.Icon = ((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.IsMdiConta iner = true;
this.Menu = this.mnuMain;
this.Name = "frmStrikeTourn ament";
this.Text = "Strike Tournament .NET";
this.WindowStat e = System.Windows. Forms.FormWindo wState.Maximize d;
this.Load += new System.EventHan dler(this.frmSt rikeTournament_ Load);

}
#endregion

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

private void mnuSystemExit_C lick(object sender, System.EventArg s e)
{
this.Dispose();
}

private void frmStrikeTourna ment_Load(objec t sender, System.EventArg s e)
{
// Calling from here works
fine...
EnableMenuOnLog in();
}

private void mnuSystemAdminL ogin_Click(obje ct sender, System.EventArg s e)
{
frmLogin newMDIChild = new frmLogin();
newMDIChild.Mdi Parent = this;
newMDIChild.Sho w();
}

private void mnuSystemSelect System_Click(ob ject sender, System.EventArg s e)
{

}

public void EnableMenuOnLog in()
{
// public, but doesn't seem
to be visible for the other form
this.mnuSystemS electSystem.Ena bled = true;
}
}
}
frmLogin:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace StrikeTournamen t
{
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.Componen tModel.Containe r components = null;

public frmLogin()
{
InitializeCompo nent();
}

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

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
System.Resource s.ResourceManag er resources = new
System.Resource s.ResourceManag er(typeof(frmLo gin));
this.gbxLogin = new System.Windows. Forms.GroupBox( );
this.txtPasswor d = new System.Windows. Forms.TextBox() ;
this.txtUserId = new System.Windows. Forms.TextBox() ;
this.btnLogin = new System.Windows. Forms.Button();
this.lblPasswor d = new System.Windows. Forms.Label();
this.lblUserId = new System.Windows. Forms.Label();
this.gbxLogin.S uspendLayout();
this.SuspendLay out();
//
// gbxLogin
//
this.gbxLogin.C ontrols.Add(thi s.txtPassword);
this.gbxLogin.C ontrols.Add(thi s.txtUserId);
this.gbxLogin.C ontrols.Add(thi s.btnLogin);
this.gbxLogin.C ontrols.Add(thi s.lblPassword);
this.gbxLogin.C ontrols.Add(thi s.lblUserId);
this.gbxLogin.L ocation = new System.Drawing. Point(8, 8);
this.gbxLogin.N ame = "gbxLogin";
this.gbxLogin.S ize = new System.Drawing. Size(288, 96);
this.gbxLogin.T abIndex = 0;
this.gbxLogin.T abStop = false;
this.gbxLogin.T ext = "Administra tor login";
//
// txtPassword
//
this.txtPasswor d.Location = new System.Drawing. Point(144, 40);
this.txtPasswor d.Name = "txtPasswor d";
this.txtPasswor d.Size = new System.Drawing. Size(136, 20);
this.txtPasswor d.TabIndex = 4;
this.txtPasswor d.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.L ocation = new System.Drawing. Point(208, 64);
this.btnLogin.N ame = "btnLogin";
this.btnLogin.S ize = new System.Drawing. Size(72, 24);
this.btnLogin.T abIndex = 2;
this.btnLogin.T ext = "&Login";
this.btnLogin.C lick += new System.EventHan dler(this.btnLo gin_Click);
//
// lblPassword
//
this.lblPasswor d.Location = new System.Drawing. Point(8, 44);
this.lblPasswor d.Name = "lblPasswor d";
this.lblPasswor d.Size = new System.Drawing. Size(136, 16);
this.lblPasswor d.TabIndex = 1;
this.lblPasswor d.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.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(304, 310);
this.Controls.A dd(this.gbxLogi n);
this.Icon = ((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.Name = "frmLogin";
this.ShowInTask bar = false;
this.StartPosit ion = System.Windows. Forms.FormStart Position.Center Parent;
this.Text = "Administra tor login";
this.Load += new System.EventHan dler(this.frmLo gin_Load);
this.gbxLogin.R esumeLayout(fal se);
this.ResumeLayo ut(false);

}
#endregion

private void frmLogin_Load(o bject sender, System.EventArg s e)
{

}

private void btnLogin_Click( object sender, System.EventArg s e)
{
// Call from here errors,
seems to be looking locally for the method, not the public one in the other
form
EnableMenuOnLog in();
}
}
}
"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**@discussion s.microsoft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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\V isual Studio Projects\Tourna ment\Forms\frmL ogin.cs(69): The
name 'test' does not exist in the class or namespace 'Tournament.frm Login'

frmLogin is the mdichild.

What am I missing here?

Thanks,
Claus Holm


Nov 16 '05 #4
Hi Claus,

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

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

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

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

((frmStrikeTour nament)this.Mdi Parent).EnableM enuOnLogin();

--
HTH
Stoitcho Goutsev (100) [C# MVP]
"Claus Holm" <Cl*******@disc ussions.microso ft.com> wrote in message
news:AF******** *************** ***********@mic rosoft.com...
Some more code from the 2 forms:

frmStrikeTourna ment:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace StrikeTournamen t
{
public class frmStrikeTourna ment : 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 mnuSystemSelect System;
private System.Windows. Forms.MenuItem mnuSystemSepera tor1;
private System.Windows. Forms.MenuItem mnuSystemAdminL ogin;
private System.Windows. Forms.MenuItem mnuSystemSetup;
private System.Windows. Forms.MenuItem mnuSystemSepera tor2;
private System.Windows. Forms.MenuItem mnuHelp;
private System.Windows. Forms.MenuItem mnuHelpHelp;
private System.Windows. Forms.MenuItem mnuHelpAbout;
private System.Windows. Forms.MenuItem mnuSystemSetupT ournament;
private System.Windows. Forms.MenuItem mnuSystemSetupC ategory;
private System.Windows. Forms.MenuItem mnuSystemSetupR ow;

private System.Componen tModel.Containe r components = null;

public frmStrikeTourna ment()
{
InitializeCompo nent();
}

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

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
System.Resource s.ResourceManag er resources = new
System.Resource s.ResourceManag er(typeof(frmSt rikeTournament) );
this.mnuMain = new System.Windows. Forms.MainMenu( );
this.mnuSystem = new System.Windows. Forms.MenuItem( );
this.mnuSystemS electSystem = new System.Windows. Forms.MenuItem( );
this.mnuSystemS eperator1 = new System.Windows. Forms.MenuItem( );
this.mnuSystemA dminLogin = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etup = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etupTournament = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etupCategory = new System.Windows. Forms.MenuItem( );
this.mnuSystemS etupRow = new System.Windows. Forms.MenuItem( );
this.mnuSystemS eperator2 = new System.Windows. Forms.MenuItem( );
this.mnuSystemE xit = new System.Windows. Forms.MenuItem( );
this.mnuHelp = new System.Windows. Forms.MenuItem( );
this.mnuHelpHel p = new System.Windows. Forms.MenuItem( );
this.mnuHelpAbo ut = new System.Windows. Forms.MenuItem( );
//
// mnuMain
//
this.mnuMain.Me nuItems.AddRang e(new System.Windows. Forms.MenuItem[] {
this.mnuSystem,
this.mnuHelp});
//
// mnuSystem
//
this.mnuSystem. Index = 0;
this.mnuSystem. MenuItems.AddRa nge(new System.Windows. Forms.MenuItem[] {
this.mnuSystemS electSystem,
this.mnuSystemS eperator1,
this.mnuSystemA dminLogin,
this.mnuSystemS etup,
this.mnuSystemS eperator2,
this.mnuSystemE xit});
this.mnuSystem. Text = "&System";
//
// mnuSystemSelect System
//
this.mnuSystemS electSystem.Ena bled = false;
this.mnuSystemS electSystem.Ind ex = 0;
this.mnuSystemS electSystem.Tex t = "&Vælg system";
this.mnuSystemS electSystem.Cli ck += new
System.EventHan dler(this.mnuSy stemSelectSyste m_Click);
//
// mnuSystemSepera tor1
//
this.mnuSystemS eperator1.Index = 1;
this.mnuSystemS eperator1.Text = "-";
//
// mnuSystemAdminL ogin
//
this.mnuSystemA dminLogin.Index = 2;
this.mnuSystemA dminLogin.Short cut = System.Windows. Forms.Shortcut. CtrlA;
this.mnuSystemA dminLogin.Text = "Administra tor &login";
this.mnuSystemA dminLogin.Click += new
System.EventHan dler(this.mnuSy stemAdminLogin_ Click);
//
// mnuSystemSetup
//
this.mnuSystemS etup.Enabled = false;
this.mnuSystemS etup.Index = 3;
this.mnuSystemS etup.MenuItems. AddRange(new
System.Windows. Forms.MenuItem[] {
this.mnuSystemS etupTournament,
this.mnuSystemS etupCategory,
this.mnuSystemS etupRow});
this.mnuSystemS etup.Text = "&Opsætning af stævne";
//
// mnuSystemSetupT ournament
//
this.mnuSystemS etupTournament. Index = 0;
this.mnuSystemS etupTournament. Text = "&Stævne";
//
// mnuSystemSetupC ategory
//
this.mnuSystemS etupCategory.In dex = 1;
this.mnuSystemS etupCategory.Te xt = "&Kategori" ;
//
// mnuSystemSetupR ow
//
this.mnuSystemS etupRow.Index = 2;
this.mnuSystemS etupRow.Text = "&Række";
//
// mnuSystemSepera tor2
//
this.mnuSystemS eperator2.Index = 4;
this.mnuSystemS eperator2.Text = "-";
//
// mnuSystemExit
//
this.mnuSystemE xit.Index = 5;
this.mnuSystemE xit.Shortcut = System.Windows. Forms.Shortcut. CtrlX;
this.mnuSystemE xit.Text = "&Afslut";
this.mnuSystemE xit.Click += new
System.EventHan dler(this.mnuSy stemExit_Click) ;
//
// mnuHelp
//
this.mnuHelp.In dex = 1;
this.mnuHelp.Me nuItems.AddRang e(new System.Windows. Forms.MenuItem[] {
this.mnuHelpHel p,
this.mnuHelpAbo ut});
this.mnuHelp.Te xt = "&Hjælp";
//
// mnuHelpHelp
//
this.mnuHelpHel p.Index = 0;
this.mnuHelpHel p.Shortcut = System.Windows. Forms.Shortcut. F1;
this.mnuHelpHel p.Text = "Strike Tournament .NET hjælp";
//
// mnuHelpAbout
//
this.mnuHelpAbo ut.Index = 1;
this.mnuHelpAbo ut.Text = "&Om Strike Tournament .NET";
//
// frmStrikeTourna ment
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(736, 449);
this.Icon = ((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.IsMdiConta iner = true;
this.Menu = this.mnuMain;
this.Name = "frmStrikeTourn ament";
this.Text = "Strike Tournament .NET";
this.WindowStat e = System.Windows. Forms.FormWindo wState.Maximize d;
this.Load += new System.EventHan dler(this.frmSt rikeTournament_ Load);

}
#endregion

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

private void mnuSystemExit_C lick(object sender, System.EventArg s e)
{
this.Dispose();
}

private void frmStrikeTourna ment_Load(objec t sender, System.EventArg s e)
{
// Calling from here works
fine...
EnableMenuOnLog in();
}

private void mnuSystemAdminL ogin_Click(obje ct sender, System.EventArg s e)
{
frmLogin newMDIChild = new frmLogin();
newMDIChild.Mdi Parent = this;
newMDIChild.Sho w();
}

private void mnuSystemSelect System_Click(ob ject sender, System.EventArg s
e)
{

}

public void EnableMenuOnLog in()
{
// public, but doesn't seem
to be visible for the other form
this.mnuSystemS electSystem.Ena bled = true;
}
}
}
frmLogin:

using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;

namespace StrikeTournamen t
{
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.Componen tModel.Containe r components = null;

public frmLogin()
{
InitializeCompo nent();
}

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

#region Windows Form Designer generated code
private void InitializeCompo nent()
{
System.Resource s.ResourceManag er resources = new
System.Resource s.ResourceManag er(typeof(frmLo gin));
this.gbxLogin = new System.Windows. Forms.GroupBox( );
this.txtPasswor d = new System.Windows. Forms.TextBox() ;
this.txtUserId = new System.Windows. Forms.TextBox() ;
this.btnLogin = new System.Windows. Forms.Button();
this.lblPasswor d = new System.Windows. Forms.Label();
this.lblUserId = new System.Windows. Forms.Label();
this.gbxLogin.S uspendLayout();
this.SuspendLay out();
//
// gbxLogin
//
this.gbxLogin.C ontrols.Add(thi s.txtPassword);
this.gbxLogin.C ontrols.Add(thi s.txtUserId);
this.gbxLogin.C ontrols.Add(thi s.btnLogin);
this.gbxLogin.C ontrols.Add(thi s.lblPassword);
this.gbxLogin.C ontrols.Add(thi s.lblUserId);
this.gbxLogin.L ocation = new System.Drawing. Point(8, 8);
this.gbxLogin.N ame = "gbxLogin";
this.gbxLogin.S ize = new System.Drawing. Size(288, 96);
this.gbxLogin.T abIndex = 0;
this.gbxLogin.T abStop = false;
this.gbxLogin.T ext = "Administra tor login";
//
// txtPassword
//
this.txtPasswor d.Location = new System.Drawing. Point(144, 40);
this.txtPasswor d.Name = "txtPasswor d";
this.txtPasswor d.Size = new System.Drawing. Size(136, 20);
this.txtPasswor d.TabIndex = 4;
this.txtPasswor d.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.L ocation = new System.Drawing. Point(208, 64);
this.btnLogin.N ame = "btnLogin";
this.btnLogin.S ize = new System.Drawing. Size(72, 24);
this.btnLogin.T abIndex = 2;
this.btnLogin.T ext = "&Login";
this.btnLogin.C lick += new System.EventHan dler(this.btnLo gin_Click);
//
// lblPassword
//
this.lblPasswor d.Location = new System.Drawing. Point(8, 44);
this.lblPasswor d.Name = "lblPasswor d";
this.lblPasswor d.Size = new System.Drawing. Size(136, 16);
this.lblPasswor d.TabIndex = 1;
this.lblPasswor d.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.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(304, 310);
this.Controls.A dd(this.gbxLogi n);
this.Icon = ((System.Drawin g.Icon)(resourc es.GetObject("$ this.Icon")));
this.MaximizeBo x = false;
this.MinimizeBo x = false;
this.Name = "frmLogin";
this.ShowInTask bar = false;
this.StartPosit ion = System.Windows. Forms.FormStart Position.Center Parent;
this.Text = "Administra tor login";
this.Load += new System.EventHan dler(this.frmLo gin_Load);
this.gbxLogin.R esumeLayout(fal se);
this.ResumeLayo ut(false);

}
#endregion

private void frmLogin_Load(o bject sender, System.EventArg s e)
{

}

private void btnLogin_Click( object sender, System.EventArg s e)
{
// Call from here errors,
seems to be looking locally for the method, not the public one in the
other
form
EnableMenuOnLog in();
}
}
}
"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**@discussion s.microsoft.com> wrote in message
news:CE******** *************** ***********@mic rosoft.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\V isual Studio Projects\Tourna ment\Forms\frmL ogin.cs(69):
> The
> name 'test' does not exist in the class or namespace
> 'Tournament.frm Login'
>
> frmLogin is the mdichild.
>
> What am I missing here?
>
> Thanks,
> Claus Holm


Nov 16 '05 #5
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
EnableMenuOnLog in();
}

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

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

((frmStrikeTour nament)this.Mdi Parent).EnableM enuOnLogin();

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


Nov 16 '05 #6
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1116
by: Kathy D | last post by:
I have created an mdi parent form with four children. I want to disable closing the four children but allow closing the parent form. I created a FormClosing event on each form. That event tests to see who the sender is. If it is the appropriate child form the close is disabled and a message box shown. The problem is on the FormClosing event for the parent. It goes immediately to the first child form and displays the message box, then...
3
3945
by: Omar Llanos | last post by:
I have Form1 and Form2 (which is inherited from Form1), and I created a button in Form2 that will fill up a textbox in Form1. What code would do that? I tried the simplest way: //from child form in button2 clicked event: textbox1.Text = "Hello";
4
2212
by: Thorsten Ottosen | last post by:
Dear all, Is it possible to close or hide a parent form? In particular, is it possible to do from the child form itself? Thanks Thorsten
1
3076
by: Sylvain | last post by:
Hi, I am developping a Visual C++ application. In my application, I created a Mdi parent form with a main menu. I also created a "menuItem" click to display a Mdi child form. I want in this case to display the Mdi child form in all the Mdi parent form. The problem is that the Mdi child form seems to be minized in his parent ( The Mdi parent form ). I have to use the "Maximize" icon of the mdi child form to make it displayed in all the...
0
1163
by: jim | last post by:
I'm using Visual Studio 2005 and .Net 2.0. When I maximize my Child form, the title bar of the Child form will overtake the parent form's menu bar
2
2907
by: Paul | last post by:
Hi this is related to a previous post, hopefully just a bit clearer description o the problem. I have a parent form that opens a new form (child form) while still leaving the parent form open. Although the child form has a close button (with java script) if the user navigates the parent form to another form the child form is still open. Just wondering if there is a way to close the child form when the user navigates away with the parent...
6
1539
by: Uncle_Albert | last post by:
Hi there, Trying to get to grips with MDI applications at the mo and having a bit of trouble with the basics. What I have at the mo is the parent form loading and immediately displaying a child form, which is to be used to log in to the system (username and password entry). When the user clicks connect on the child form, I want the menu's on the parent to become enabled.
2
2444
by: Matt | last post by:
Ok here is my problem: I have a MDI parent form called "Main" that I declare in a public module when I start up my program. This form holds the drop down menu that allows my users to access all of the child forms. Now lets say I have a child form called "Child." When I open up that child form from "Main" I shut off the menu on "Main" so that the user cannot open up any other forms while they are in the "Child" form.
0
948
by: anishanc | last post by:
Hai dear I have a sales form that contains a button to create new item, when the item's form is displayed i just disable the sales form. My question is that how can i enable the sales form while closing the item's form.? Item form is dynamically used by many other forms. Now I just setting sales class object to a static variable in the items class, and I using this sales object to enable sales form. (eg: sales class object ....
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9236
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9182
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.