Solved

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

Posted on 2006-11-03
5
867 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
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C#.NET and microsoft certification. 3 40
Programmatically storing deadlock graphs with SQL Server 6 41
FTP file download using c# 3 23
.NET 2008 VB and C# 6 27
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

770 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