Solved

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

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

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 86

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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