文本框未显示在第一个标签页上

时间:2015-07-21 13:27:33

标签: c# .net winforms tabcontrol

我正在制作一个应用程序,要求我在每个tabPage上动态添加带有textBox和标签的tabPages(默认配置tabControl中没有tabPages)。在第一个标签页上,没有显示任何文本框。具有讽刺意味的是,标签总是存在......只是没有文本框。当我尝试通过tabControlLanguageTranslations.SelectedTab.GetChildAtPoint(translationTextbox)在另一个函数中访问它时,它会出现空值。此问题仅发生在第一个tabPage上。

以下是创建文本框和标签的代码:

foreach (var lang in languages)
            {
                TabPage tempTab = new TabPage(lang.shortName);

                TextBox TextBoxStringTranslation = new TextBox();
                Label LabelTranslation = new Label();

                TextBoxStringTranslation.Location = translationTextbox;
                TextBoxStringTranslation.Width = 300;
                TextBoxStringTranslation.Height = 200;
                TextBoxStringTranslation.Multiline = true;
                TextBoxStringTranslation.TextChanged += TextBoxStringTranslation_TextChanged;

                LabelTranslation.Location = new Point(10, 10);
                LabelTranslation.Width = 100;
                LabelTranslation.Text = "Translation:";

                tempTab.Controls.Add(TextBoxStringTranslation);
                tempTab.Controls.Add(LabelTranslation);
                langTabs.Add(tempTab);

                tabControlLanguageTranslations.TabPages.Add(langTabs[langTabs.Count -1]);

                tempTab = null; //destroys the object because passing by reference would give us hell
            }

0 个答案:

没有答案