Solved

C# Winform panel within a panel

Posted on 2016-09-28
4
64 Views
Last Modified: 2016-10-03
I have a panel(child panel) inside another panel (parent panel).  When the parent panel gets resized, I want to resize the child panel to some ration of the parent panel.
The trick is that I don't know the best practice method of doing this.   Right now, I manually call the child panel resize event from the parent's resize event.  That looks sloppy to me.
Plus, while in the child resize event, I get the parent's rectangle, and use that to set the child's rectangle.  This also seems to cause another resize event to trigger....   Really sloppy.
What is the best practice to do this?

thanks!
0
Comment
Question by:roujesky
[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
4 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41820294
can't you just rely on the Anchor property of the controls?
0
 

Author Comment

by:roujesky
ID: 41820433
Depending on some external situations, I may want to make the panel bigger or smaller or change the background color of it.  Also, the child panel will have different components visible or invisible, etc....

thanks!
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 41820445
that means that you have complex code running each time the resize event is triggered. instead of redoing this logic every time (which can hundreds of times every second, I would start a timer if not already started that would only do the resizing logic on the Tick event. You will need to test how long you will set the timer to (can probably be something like 250 ms).
1
 
LVL 30

Accepted Solution

by:
anarki_jimbel earned 500 total points
ID: 41820910
If you use a (parent) form to resize panels then you may use the ResizeEnd event to do some actions after resizing. E.g.:

namespace ResizingTest
{
    public partial class Form1 : Form
    {
        Size initialSize;
        Size resultingSize;

        public Form1()
        {
            InitializeComponent();
        }

 

        private void Form1_ResizeBegin(object sender, EventArgs e)
        {
            initialSize = this.panel1.Size;
            System.Diagnostics.Debug.WriteLine("FORM RESIZE - - - BEGIN");
        }

        private void Form1_ResizeEnd(object sender, EventArgs e)
        {
            resultingSize = this.panel1.Size;
            if (initialSize != resultingSize)
            {
                System.Diagnostics.Debug.WriteLine("##### --- SIZE CHANGED - - - DO YOUR JOB!!! - - - #####");
            }

            System.Diagnostics.Debug.WriteLine("FORM RESIZE - - - END");
        }
    }
}

Open in new window

0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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
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…

726 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