Solved

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

Posted on 2006-11-03
5
861 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
  • 2
  • 2
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
Try setting Dock to Fill:

    frm.Dock = DockStyle.Fill;
0
 
LVL 6

Accepted Solution

by:
so3 earned 75 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Idle_Mind,
yes you're right:)

thanks
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now