Solved

how to resize a form put inside a tabpage and keep it in sinc with main form???

Posted on 2006-11-03
5
872 Views
Last Modified: 2007-12-19
Hello

I have this tabcontrol that I put in my main form. It has three tabpages.
On the first tab I want to display a user form and I want to resize it so it matches that size on the tabcontrol. I also need to make sure the form follows the resize of the main form and the tabcontrol...

This is the code I use in the mainform's page load event to set up my user form:
        private void frmMain_Load(object sender, EventArgs e)
        {
            Form1 frm= new Form1(); // the user form to display in tab #0
            frm.TopLevel = false;
            frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            frm.WindowState = FormWindowState.Normal;
            tabControl1.TabPages[0].Controls.Add(frm);
            frm.Show();
        }


Which event(s) do I need to redefine? and how to figure out the size on the form inside the tab relative to the main form and the tabcontrol?

I want everithing to be resized together, the mainform, the tabcontrol and the tabs...

thanks  in advance
0
Comment
Question by:aquila98
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17871045
Try setting Dock to Fill:

    frm.Dock = DockStyle.Fill;
0
 
LVL 6

Accepted Solution

by:
so3 earned 75 total points
ID: 17872627
First of all you will get an error in your code when you use frm.show, because you can't use a form inside another control. use instead a usercontrol

Try this:

 private void frmMain_Load(object sender, EventArgs e)
        {
            UserControl frm = new UserControl(); // the user form to display in tab #0
            tabControl1.TabPages[0].Controls.Add(frm);
            frm.BackColor = Color.Red; // use this to see that the control is fully resized, delete this line after seeing
            frm.Dock = DockStyle.Fill;
        }

I saw that you use Form1 if this is a class made by you to show something then  change the class type from Form to UserControl and then use it in the frmMain_Load event.



0
 
LVL 2

Author Comment

by:aquila98
ID: 17872898
I gave points to so3 because solution was also about inheritance of userform instead of form...

thanks a lot.

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17873352
But for the record so3, you CAN show a form inside a container as long as the TopLevel() property is False:

    frm.TopLevel = false;

Try it for yourself please...

(aquila98 already this set in fact)
0
 
LVL 6

Expert Comment

by:so3
ID: 17873811
Idle_Mind,
yes you're right:)

thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question