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
Solved

C# Winform panel within a panel

Posted on 2016-09-28
4
58 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
  • 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 29

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
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…

840 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