Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
I have a button, that when clicked it creates and displays various controls such as, text boxes and labels.
However, I want it to display on a Tabpage. At the moment it shows up on the original form background.
而不是this.Controls.Add(...),您可以将其添加到您想要的TabPage而不是tabPage1.Controls.Add(...).
this.Controls.Add(...)
TabPage
tabPage1.Controls.Add(...)
或者,如果您正在创建一个新的TabPage,请将控件添加到其中,然后添加TabPage到TabControl:
TabControl
TabPage tp = new TabPage(); tp.Text = "New Tab"; TextBox tb = new TextBox(); tp.Controls.Add(tb); tabControl1.TabPages.Add(tp);