从孩子更改MDI父母的财产? [英] Change property on MDI parrent from child?

查看:97
本文介绍了从孩子更改MDI父母的财产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有以下三种形式:
frmMainfrmLoginfrmPanel.


当我运行程序时,它显示frmMain这是一个MDI容器,并在加载时以子级形式打开登录"表单.

现在,当我登录并且信息正确时,我需要启用toolstrip1上的按钮,这些按钮在加载时被禁用.

我尝试过的是在frmMain
中创建一个函数

Hello there,

I have three forms:
frmMain, frmLogin and frmPanel.


When I run my program it shows frmMain which is an MDI container, and on load I open Login form as child.

Now when I login and information is correct I need to enable buttons on my toolstrip1 which are disabled on load.

What I''ve tried is to make a function inside frmMain

void functionOnForm1()
{
    this.toolStripButton7.Enabled = true;
}


然后在密码确定后在登录表单上调用此函数:


then on login form after password is OK I call this function:

((frmMain)this.MdiParent).functionOnForm1();


但出现以下错误:
由于其保护级别(CS0122),无法访问"Project1.frmMain.functionOnForm1()".

这是frmMain:


but I get the following error:
''Project1.frmMain.functionOnForm1()'' is inaccessible due to its protection level (CS0122).

This is frmMain:

public partial class frmMain  : Form
{
    public frmMain()
    {
        InitializeComponent();
    }

    void functionOnForm1()
    {
        MessageBox.Show("ddd");
    }
}


推荐答案

您有两种选择.

frmMain中公开该方法,或者在frmLogin中沿 ^ ].

在MDI应用程序中,我通常更喜欢第一种(更简便的)方法.
You have two choices.

Either make the method in frmMain public, or raise an event in frmLogin along the lines of this[^].

In a MDI application I normally prefer the first (easier) approach.


请将您的代码放在代码块标签中.它使我们更轻松地阅读您的代码.

[添加]我已经代表OP DaveyM69编辑了问题. [/添加]
Please place your code in the code block tags. It makes it much easier for us to read your code.

[Added] I''ve edited the question on behalf of the OP, DaveyM69. [/Added]


这篇关于从孩子更改MDI父母的财产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆