2013-12-19 108 views
0

我尝试使用UserControl开发应用程序。我的MainForm上有一个TableLayoutPanel动态地为不同的UserControls充电。其中一个UserControl包含一个FlowLayoutPanel,其中动态加载按钮。开始时,此FlowLayoutPanel(带有12个按钮)为Enabled = false。我的问题是,如果我点击我的MainForm上的一个按钮,我想从我的UserControl的FlowLayoutPanel(有12个按钮)变为Enabled = true。我的FlowLayoutPanel(有12个按钮)的状态为Enabled = true,但我的FlowLayoutPanel和我的按钮未激活。状态是好的,但实际上我不能点击我的按钮,因为他们不活跃。我会忘记一些事情吗?这不可能吗?UserControls并激活按钮

下面是我的一些代码:

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类型使用”是不是好,我用你的代码?

我使用什么类型?

谢谢

回答

0

很难从您的代码中知道。 尝试手动做

MyFlowLayoutPanel.Enabled += MyFlowLayoutPanel_EnabledChanged(); 

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

您好,感谢您的帮助。 – Paintbox