【问题标题】:UserControls and activate buttons用户控件和激活按钮
【发布时间】:2013-12-19 21:57:15
【问题描述】:

我尝试使用 UserControls 开发应用程序。我的 MainForm 上有一个 TableLayoutPanel 动态地对不同的 UserControl 进行收费。此 UserControl 之一包含动态加载按钮的 FlowLayoutPanel。一开始,这个 FlowLayoutPanel(有 12 个按钮)是 Enabled = false。我的问题是,如果我单击 MainForm 上的一个按钮,我希望我的 UserControl 中的 FlowLayoutPanel(带有 12 个按钮)变为 Enabled = true。我的 FlowLayoutPanel(有 12 个按钮)的状态为 Enabled = true 但我的 FlowLayoutPanel 和我的按钮未激活。状态还可以,但实际上我无法单击我的按钮,因为它们未处于活动状态。我会忘记什么吗?这不可能吗?

这是我的一些代码:

public void OpenCaisseDialog()
{
   System.Windows.Forms.DialogResult OpenCashDialog = new DialogResult();
   OpenCaisseForm OCF = new OpenCaisseForm();
   OpenCashDialog = OCF.ShowDialog();
   if(OpenCashDialog == System.Windows.Forms.DialogResult.OK)
   {
      if ((Convert.ToInt32(OCF.tbMontantOuverture.Text)) > 0)
      {
         PanelTables.Controls.Clear();
         PanelTables.Enabled = true;
         PanelTables.Refresh();
      }
      else
      {
         MessageBox.Show("La somme en caisse est égale à 0");
      }
   }
   PanelTables.Refresh();
}

感谢您的帮助。我试过你的代码,但我不知道我是否使用它。我这样做:

 public void OpenCaisseDialog()
    {
        System.Windows.Forms.DialogResult OpenCashDialog = new DialogResult();
        OpenCaisseForm OCF = new OpenCaisseForm();
        OpenCashDialog = OCF.ShowDialog();

        if(OpenCashDialog == System.Windows.Forms.DialogResult.OK)
        {
            if ((Convert.ToInt32(OCF.tbMontantOuverture.Text)) > 0)
            {
                PanelTables.Enabled += MyFlowLayoutPanel_EnabledChanged();
                PanelTables.Refresh();
            }
            else
            {
                MessageBox.Show("Sum isn't equals 0");
            }
        }
        PanelTables.Refresh();
    }


    private void MyFlowLayoutPanel_EnabledChanged()
    {
        foreach(Control c in this.PanelTables.Controls)
        {
            c.Enabled = this.PanelTables.Enabled;
        }
    }

我对那行有错误:PanelTables.Enabled += MyFlowLayoutPanel_EnabledChanged();

“+= 不能与 bool 和 void 类型一起使用”

我用你的代码好吗?

我用什么类型的?

谢谢

【问题讨论】:

    标签: .net winforms c#-4.0


    【解决方案1】:

    很难从您的代码中分辨出来。 尝试手动操作

    MyFlowLayoutPanel.Enabled += MyFlowLayoutPanel_EnabledChanged();
    
    private void MyFlowLayoutPanel_EnabledChanged()
    {
        foreach(Control c in MyFlowLayoutPanel.Controls)
        {
            c.Enabled = MyFlowLayoutPanel.Enabled;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-15
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      • 2014-05-28
      • 1970-01-01
      相关资源
      最近更新 更多