简体   繁体   English

C#动态添加的GroupBox向其添加控件后似乎为空

[英]C# dynamically added GroupBox seems to be empty after adding controls to it

I am having trouble with a little tool i am writing for myself. 我在为自己编写的小工具上遇到麻烦。 I am trying to have a Windows Form that shows a web browser and multiple, dynamically added groups of textboxes and comboboxes. 我正在尝试使用一个显示Web浏览器的Windows窗体以及多个动态添加的文本框和组合框组。 The browser works fine and i can add textboxes etc. fine when not adding it to a groupbox, but rather to the main panel. 浏览器工作正常,当不将其添加到组框而不是主面板时,我可以添加文本框等。

When trying to add the textboxes to groupboxes it works for the first groupbox, but every other one that followes stayes empty. 尝试将文本框添加到组框时,它适用于第一个组框,但后面的所有其他框均保持空白。

this is how my (simplified) code looks so far: 到目前为止,这是我的(简化)代码的样子:

        //generate controls e.g.
        ComboBox dynamicComboBox = new ComboBox();
        dynamicComboBox.Name = "comboBox" + anzahlModule;
        dynamicComboBox.DataSource = new BindingSource(this.getInhaltComboBox(), null);
        dynamicComboBox.DisplayMember = "Value";
        dynamicComboBox.ValueMember = "Key";
        dynamicComboBox.Location = new System.Drawing.Point(153, Yloc + 25);
        dynamicComboBox.TabIndex = tabReihenfolge + 2;
        dynamicComboBox.SelectedIndexChanged += comboBox1_SelectedIndexChanged;

        ...do for all the others...


        //Get Interface and redraw
        GroupBox dynamicGroup = new GroupBox();
        dynamicGroup.Text = dynamicLabel.Text;
        dynamicGroup.Size = new System.Drawing.Size(600, 325);
        dynamicGroup.Location = button1.Location;
        dynamicGroup.Name = "dynamicGroupBox" + anzahlModule;
        dynamicGroup.Visible = true;

        dynamicGroup.Controls.Add(LabelComboBox);
        dynamicGroup.Controls.Add(LabelTextBox);
        dynamicGroup.Controls.Add(LabelTextBox2);
        dynamicGroup.Controls.Add(LabelInhalt);
        dynamicGroup.Controls.Add(LabelInhalt2);
        dynamicGroup.Controls.Add(LabelPictures);
        dynamicGroup.Controls.Add(LabelCheckBox);
        dynamicGroup.Controls.Add(LabelCheckBox2);
        dynamicGroup.Controls.Add(LabelLink);
        dynamicGroup.Controls.Add(LabelLink2);
        dynamicGroup.Controls.Add(dynamicTextBox);
        dynamicGroup.Controls.Add(dynamicTextBox2);
        dynamicGroup.Controls.Add(dynamicUeberschrift);
        dynamicGroup.Controls.Add(dynamicUeberschrift2);
        dynamicGroup.Controls.Add(dynamicComboBox);
        dynamicGroup.Controls.Add(dynamicPictureBox);
        dynamicGroup.Controls.Add(dynamicCheckBox);
        dynamicGroup.Controls.Add(dynamicCheckBox2);
        dynamicGroup.Controls.Add(dynamicLinkBox);
        dynamicGroup.Controls.Add(dynamicLinkBox2);
        panel1.Controls.Add(dynamicGroup);

this works if i add the stuff directly to panel1, but not when adding it to the groupboxes. 如果我将这些内容直接添加到panel1,但在将其添加到组框时则无效。

Can someone help my by giving me an idea on where the probleme might be or tell me what is actually wrong? 有人可以通过给我一个关于问题可能在哪里的想法或告诉我实际上是什么问题来帮助我吗?

Thanks in advance. 提前致谢。

Okay so I found my error and it is actually very simple, i was just too blind to see it :) I have positioned my textBoxes and so on in relation to a button that i afterwards moved. 好的,所以我发现了我的错误,它实际上非常简单,我实在太盲目了:)我将我的textBoxes放置在相对于我后来移动的按钮的位置上。 And that means that i tryed to display eg a label at point 750 / 300 in a group box that only has a size of 600x325, so it can not be visible. 这意味着我试图在仅大小为600x325的组框中显示例如点750/300处的标签,因此它不可见。 @Mikhail Neofitov thanks for the tip with multiple boxes at the same location, that lead to a solution. @Mikhail Neofitov感谢您在同一位置使用多个盒子的提示,这为您提供了解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM