CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2010
    Posts
    4

    Resize a form in a panel

    I am trying to resize a a form that I put inside a panel so that when the panel's window is maximized or resized, the form will size along with it. Currently, I have the form class as UserControl instead of Forms because this is the only way I could get it to work. The panel is docked center in the main window and the form is called by clicking a node in the tree docked on the left. The code I use to show the form is:

    Code:
    WinForm winfrm = new WinForm();
    pnlXVw.Controls.Add(winfrm);
    I am unsure if the UserControl is correct. The code is from the form.

    Code:
    public partial class WinForm : System.Windows.Forms.UserControl
    I have tried anchoring the form and setting the dockstyle of the form to fill. I haven't been successful with either of these. Also, I have tried setting the panel (pnlXVw) so that the form (winfrm) but can't figure out how to do that correctly. Thanks in advance!

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Resize a form in a panel

    Just to correct your terminology a bit because it is very confusing; A "Form" is defined as a class derived from Form. If your control is a UserControl it is not in any way shape or form a "Form", it is a UserControl. To speak of it as a Form is incorrect as they are very different animals. forms do not have Anchor or DockStyle properties and you cannot place a form inside of a panel.

    You need to anchor your panel on all sides and set the DockStyle of your UserControl to fill. If you do that they will resize with the parent form.

  3. #3
    Join Date
    May 2010
    Posts
    4

    Re: Resize a form in a panel

    I apologize for not using the correct terminology. I tried anchoring and setting the dockstyle to fill without success. This is what I have now:

    Code:
    UsrCtrl userCtrl = new UsrCtrl();
    userCtrl.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Left);
    userCtrl.Dock = System.Windows.Forms.DockStyle.Fill;
    pnlXVw.Controls.Add(userCtrl);
    The panel is docked in the main window. If I replace userCtrl with pnlXVw in the anchor above, my docking of the panel in the main window doesn't work correctly. It moves the panel with the window but with a 20 or so pixels in between. Also, the UserControl still doesn't move.

  4. #4
    Join Date
    Jun 2010
    Posts
    85

    Re: Resize a form in a panel

    In order to get the inner control to resize, you must change the size of parent panel, you know that right? The inner control will size with the parent panel.

    Also get rid of all the AnchorStyle stuff, it is redundant DockStyle.Fill does the job just fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured