how do i put controls at run-time in tabs created at run-time in a tabcontrol?
Printable View
how do i put controls at run-time in tabs created at run-time in a tabcontrol?
VB Code:
Dim txt As New TextBox() TabControl1.Controls.Add(txt) txt.Visible=True txt.Location=New Point(0,0)
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll
Additional information: Cannot add 'TextBox' to TabControl. Only TabPages can be directly added to TabControls.
Opps that is my bad, you have to add it to the TabPage1.Controls collection not the tabcontrol itself, sorry. If there are no tabpages then you can add one to the tab control then add the controls to it.
VB Code:
Dim tp As New TabPage() TabControl1.Controls.Add(tp) Dim txt As New TextBox() tp.Controls.Add(txt) txt.Visible=True txt.Location=New Point(0,0)
yea lol
i have a question..imagine i want to create tabs at run-time and create in them textbox's at run-time..how do i do that?
That is exactly what that does. You'll probably want to change the location to something other than the very top left most corner though.Quote:
Originally posted by Edneeis
VB Code:
Dim tp As New TabPage() TabControl1.Controls.Add(tp) Dim txt As New TextBox() tp.Controls.Add(txt) txt.Visible=True txt.Location=New Point(0,0)
yea lol i suck
ah tks did what i want :
PHP Code:private void button2_Click(object sender, System.EventArgs e)
{
TabPage tpTab = new TabPage(tabControl1.TabPages.Count.ToString());
tabControl1.TabPages.Add(tpTab);
TextBox ttBox = new TextBox(); ttBox.Text = (tabControl1.TabPages.Count - 1).ToString();
tpTab.Controls.Add(ttBox);
}