Hi,
I am trying to add a TabPage containing a UserControl to a TabControl at runtime, because the number of TabPages to add are determined at runtime.
The UserControl (objDataInfo) is just two Textboxes, two labels and two Radiobuttons, nothing too exciting...
The TextBoxes have their Anchor properties set to Left, Up, Right so they scale with the width of the usercontrol.
The TabPages are added in the constructor of the form, which takes the number of tabpages to create (n) as an argument:
vb.net Code:
Dim cList As List(Of objDataInfo) Public Sub New(ByVal n As Integer) InitializeComponent() Dim t As TabPage Dim c As objDataInfo cList = New List(Of objDataInfo) 'Create tabpages on the fly For i As Integer = 1 To n t = New TabPage("Objective " & i.ToString) c = New objDataInfo(i) tab.TabPages.Add(t) c.Dock = DockStyle.Fill c.BackColor = t.BackColor t.Controls.Add(c) cList.Add(c) Next End Sub
The cList is just a list so I can reference the controls later.
The problem is that the BackColor of the usercontrols are just the standard gray, while the BackColor of a normal TabPage is not (at least not on all themes). As far as I know it is pure white on Windows Vista, but on XP (Media Center Edition) it is some kind of blueish hue...
(I am setting the usercontrol BackColor to transparent so it should match the BackColor of the TabPage, right?)
I have also tried setting it to the BackColor of the first TabPage (which is not created at run-time so does have the correct BackColor, see image below) but that didn't work either.
Here is a screenshot of the first Tabpage (created during Design Time) with the correct BackColor (should match the standard BackColor on any theme):
And here is the second TabPage (generated at run-time) with obviously the wrong BackColor...
So... How can I get the standard BackColor of a standard TabPage?
(I tried leaving out the usercontrol all-together, but the TabPage still has a gray background...)







Reply With Quote