question

flavouslei-6337 avatar image
0 Votes"
flavouslei-6337 asked flavouslei-6337 commented

Flowlayoutpanel control in a child form can not be modified

when the father form has a flowlayoutpanel control, child form can not modify its any attribute though the modifiers of flowlayoutpanel is public. But other controls of father form like button can be modified in child form.

windows-wpf
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is your project WPF or Windows Forms?

0 Votes 0 ·

Is Winforms. I only found WPF label......

0 Votes 0 ·
DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered flavouslei-6337 commented

I test the method that provide in the SO thread, and it works fine. Here is a workaround you can refer to.
We can replace the FlowLayoutPanel with a custom FlowLayoutPanel class.

Parent.Designer.cs:

   partial class Form1
 {
     // Code omitted
     // …
         private void InitializeComponent()
         {
             flowLayoutPanel1 = new FlowLayoutPanelHeritable();
             this.SuspendLayout();
             // 
             // flowLayoutPanel1
             // 
             flowLayoutPanel1.Location = new System.Drawing.Point(24, 12);
             flowLayoutPanel1.Name = "flowLayoutPanel1";
             flowLayoutPanel1.Size = new System.Drawing.Size(285, 174);
             flowLayoutPanel1.TabIndex = 0;
             // Code omitted
             // …
         }
    
         // declare a custom FlowLayoutPanel
         public FlowLayoutPanelHeritable flowLayoutPanel1;
         public System.Windows.Forms.Button button1;
     }
    
     // Custom FlowLayoutPanel inherited from FlowLaypitPanel
     [Designer(typeof(ParentControlDesigner))]
     public class FlowLayoutPanelHeritable : FlowLayoutPanel
     {
     }

Hope this can help you.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AppreciatIve!It looks like the method at stackoverflow is good enough. Maybe this problem needs to be fixed by VS.

0 Votes 0 ·
DaisyTian-1203 avatar image
0 Votes"
DaisyTian-1203 answered flavouslei-6337 commented

What is the “child form” you mentioned? A form opened from “father form” by clicking a button? Or an MDI child form?
If is the former, I tested it and it works fine. The following is the test demo.

Parent Form:

   public FlowLayoutPanel FLP
     {
         get { return flowLayoutPanel1; }
         set { flowLayoutPanel1 = value; }
     }
    
     private void btOpenChild_Click(object sender, EventArgs e)
     {
         Form2 form = new Form2();
         form.Show();
 }

Child Form:

  private void btModifyPanel_Click(object sender, EventArgs e)
     {
         Form1 form1 = (Form1)Application.OpenForms["Form1"];
         form1.FLP.BackColor = Color.Red;
 }

10458-demo.gif
If is an MDI child form, please provide some related code to reproduce the issue.



demo.gif (26.8 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank for your help! The father form and child form I mentioned is inherited. There is someone also encounter this problem at stackoverflow. https://stackoverflow.com/questions/29509386/c-sharp-winforms-flowlayoutpanel-locking-child-controls
10390-20200623151744.png


10514-20200623151808.png


0 Votes 0 ·