Panel Dock-Style FILL and Minimum-Size at the same time on form

275 views Asked by At

I've got a panel that we want to act like it is Dock-Style-Fill but also enforce a minimum-size, having the parent form Auto-Scroll. Acting like it is Dock-style-Fill has been easy, but the scroll part is frustrating me. Very often the scroll bars will not show up, or show up about 30 pixels too small (as in there is about 30 pixels more of the panel hidden below the bottom of the form). It will eventually, after triggering the events that call the method below, correct itself, but it isn't reliable enough. I'm lost at this point and completely frustrated that I can't find any search results for doing this, or explaining what the heck the AutoScrollSize is supposed to be doing so I can try and take more educated guesses.

Summary Layout background:

<Form>
   <TableLayoutPanel Dock = TOP>
      <Resizeable Panel Dock = FILL />
      <Resizeable Panel Dock = FILL />
      <Panel that will be min of 250 Dock = FILL />
   </TableLayoutPanel>
</Form>

Basic Layout Code For setting Height

var minHeight = 250;
var buffer = 6;

var fillHeight = this.ClientSize.Height - TableLayoutPanel1.Top - (HScroll? System.Windows.Forms.SystemInformation.HorizontalScrollBarHeight:0);
var minHeightHeight = PnlWithMinHeight.Top + buffer + minHeight;

TableLayoutPanel1.Height = Math.Max(fillHeight, minHeightHeight);
TableLayoutPanel1.MinimumSize = new Size(0, minHeightHeight);

this.AutoScroll = true;
this.AutoScrollMinSize = new Size(0, this.Size.Height);

What I've Tried

  • setting the panel to FILL and adjusting the min-size.
  • Anchoring the panel on all side, and using min-size
  • Using code below with AutoScrollSize set to (0,0), (0,MinHeightHeight), or (o, ClientSize.Height). The ClientSize had nearest results, but was still unreliable
  • Changing the minHeight logic (adding or removing extra spacing)
  • Set panel to fill but the height is scrollable in windows forms

ISSUE When the form resizes or when the first 2 rows of the TableLayoutPanel are resized (controlled by user) the TableLayoutPanel should expand to fill the rest of the form, or if the resize down, up to the point the bottom panel maintains a size of 250. I think the sizing is working. The issue is that when the resizing gets triggered by one of the event handlers, the scroll bars do not always show correctly. They will not show, or not have enough scrolling to show the whole control.enter image description here

0

There are 0 answers