-1

我有两个用户控件ImportDailyReport。导入用户控件包含一个组合框,并DailyReport有一些事件,如编辑和保存。当我单击编辑按钮时,我想禁用Import用户控件上的那个组合框。DailyReport用户控制在Import用户控制之上。

我在 DailyReport 用户控件中尝试了以下代码。

public delegate void EditButtonClickEventHandler(object sender, EventArgs e);
public event EditButtonClickEventHandler OnEditClick;

private void actionControlDRD_EditEvent(object sender, EventArgs e)
{
    if (OnEditClick != null)
    {
        OnEditClick(sender, e);
    }
}

我该怎么做?

4

3 回答 3

2

在第一种形式中,我会有这样的东西。

public delegate void ButtonClickedEvent(object sender);
public event ButtonClickedEvent Form1ButtonClicked;

private void button1_Click(object sender, EventArgs e)
{
    if (Form1ButtonClicked != null)
    {
        Form1ButtonClicked(sender);
    }
}

在第二种形式中,我会有这样的东西。

public Form2()
{
    InitializeComponent();

    Form1 f = new Form1();
    f.Form1ButtonClicked += new Form1.ButtonClickedEvent(f_Form1ButtonClicked);
    f.Show();
}

void f_Form1ButtonClicked(object sender)
{
    comboBox1.Enabled = false;
}
于 2013-08-23T11:40:55.203 回答
0
private void EnableDisableControls(Control.ControlCollection Controls, bool state)
{
    foreach (Control c in Controls)
    {
        c.Enabled = state;
        if (c is ComboBox)
        {
            // do something here with comboBoxes 
        }

        if (c.Controls.Count > 0)
        {
            this.EnableDisableControls(c.Controls, state);
        }
    }
}
于 2013-08-23T11:41:44.053 回答
0

您必须在表单构造函数中为ImportDailyReport用户控件创建一个且只有一个 对象

在表单中添加两个方法

  1. 接受Import对象作为参数

无效 DisableDailyReportCombo(导入 objImport)

{

objDailyReport .Combobox.enabled=false;

}

  1. 接受DailyReportobject作为论据

无效 DisableImportCombo(DailyReport objDailyReport )

{

objDailyReport .Combobox.enabled=false`

}

并在每种方法中处理适当的功能

即,当从Import用户控件引发事件时,使用参数对象调用DisableImportComboDailyReport方法并禁用组合框

于 2013-08-23T11:44:30.833 回答