[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

C# Winform panel within a panel

Posted on 2016-09-28
4
Medium Priority
?
96 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 2000 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

656 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