Big Problem with Tabcontrol

Z

zorrothefox.groups

Hi,
I have an Windows Forms application written in C# which has a
tabcontrol in it. The tabcontrol has many pages in it. Each tabpage
deals with a specific feature in the application. e.g. Download,
Upload, Erase etc.

If I add all the controls directly to the tabpages, then that
basically means that I'd have to handle all the logic in the main form
itself. However, this would mean that the entire code for the
application would be in one class.

Hence, I need to split up the tabpages into either separate Windows
Forms OR User Controls(based on some info in earlier posts), and then
load them at Main Form's Load event into the tabcontrol.

I tried loading the forms into the tabpages by doing something like
this...

form.TopLevel = false;
form.FormBorderStyle = FormBorderStyle.None;
form.Parent = tab;
tab.Controls.Add(form);
form.Show();

Now, the problem is that even though the form displays properly in the
tab page, some part of the form seems to be missing. The right and
bottom parts of the form are not showing, even though the form size
and controls are
capable of fitting into the tabpage bounds. Also, the controls are
much larger than in the form, as if they have been zoomed up. I am
having to severely reduce the size of the form to make it display
properly, even then the control sizes are not as on the form.

The exact same problem occurs even if I use a UserControl instead of a
form to host the controls, and do the following...
UserControl1 userControl = new UserControl1();

tabPageDownload.Controls.Clear();
tabPageDownload.Controls.Add(userControl);

//this line seems to make it fit slightly better into the
tabpage, but doesn't solve the problem
userControl.Dock = DockStyle.Fill;


I have run out of ideas here. Any help would be highly welcome.
Windows Forms Gurus, please show me the light!

Thanks in advance,
Bharat
 
J

Jeff Gaines

On 24/04/2008 in message
<[email protected]>
I have run out of ideas here. Any help would be highly welcome.
Windows Forms Gurus, please show me the light!

I use the second technique you mention with user controls. I initialise
the controls:

// m_JHelpPanel
m_JHelpPanel = new JGHelp.JHelpPanel();
m_JHelpPanel.Parent = tabPageHelp;
tabPageHelp.Controls.Add(m_JHelpPanel);
m_JHelpPanel.Dock = DockStyle.Fill;

The only extra line is where I set the Parent, not sure if it's needed now
I just got into the habit when VS first came out!

I don't have problems, everything shows up as it should. Are you using
module wide variables for your controls?

The Tab Control can be a bit odd sometimes, other controls on it don't
seem to get initialised until you actually switch to the tab page so it
can be worth running through a loop selecting each Tab Page in turn during
initialisation of the app.
 
Z

zorrothefox.groups

Hi,
Finally solved the problem. The problem was that I had
changed the font of some buttons on the forms/user controls to make
them more visible. Since by default, the AutoScaleMode property for a
form is set to 'Font' (right-click on the form and select
'Properties'), the TabControl was changing the scale of the user
control to fit. Once I cleared the AutoScaleMode programmatically, the
forms AND the user controls started displaying properly without any
hassles.

Cheers,
Bharat.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top