Keeping a panel proportional
-
Hi, I want to implement a preview area which i want it to have a proportional size to the display resolution. I have a workspace which is a form which is docked fill to my main window. This is my panel size adjust function:
private void AdjustLayoutEditorSizeToDisplay(int width, int height) { int panelHeight; Console.WriteLine("Display size: " + width + " x " + height); Console.WriteLine("tpLayout size: " + this.Size.Width + "x" + this.Size.Height); Console.WriteLine("regionPanel initial size: " + regionsPanel.Size.Width + "x" + regionsPanel.Size.Height); int percent = Utility.PixelsToPercent(this.Size.Width, width); Console.WriteLine("The provided width is " + percent + "% of the maximum percentage."); if (percent > 100) { int diff = percent - 100; panelHeight = Utility.PercentToPixels(height, 100 - diff); Console.WriteLine("The height calculated based on the percentage is " + panelHeight + "."); } else { panelHeight = Utility.PercentToPixels(height, percent); Console.WriteLine("The height calculated based on the percentage is " + panelHeight + "."); } regionsPanel.Size = new Size(this.Size.Width, panelHeight); Console.WriteLine("regionPanel final size: " + regionsPanel.Size.Width + "x" + regionsPanel.Size.Height); }
I provide the resolution and suposly it will make the panel adjust its width to the workspace width and the height propotional to that. But i found a problem, when docked, a panel seems to keep its original Size property and so it will not give me a correct proportion and it will not adjust its width to the workspace width. WEll.. can somebody tell me if there is a turn around for this? Thx, Nuno