Skip to content

Commit

Permalink
Merge pull request #1941 from cwensley/curtis/winforms-tablelayout-in…
Browse files Browse the repository at this point in the history
…visible-controls

WinForms: Fix TableLayout when controls are invisible
  • Loading branch information
cwensley authored Apr 27, 2021
2 parents 1969965 + 2da7fe6 commit 5e91c71
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/Eto.WinForms/Forms/TableLayoutHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ sd.Size GetMinSize()
// is smaller than all the children
var widths = GetColumnWidths();
var heights = GetRowHeights();
if (widths.Length != columnScale.Length || heights.Length != rowScale.Length)
return sd.Size.Empty;
if (widths.Length != columnScale.Length || heights.Length != rowScale.Length)
return sd.Size.Empty;
var curSize = sd.Size.Empty;
for (int i = 0; i < widths.Length; i++)
{
Expand All @@ -60,21 +60,21 @@ protected override void SetBoundsCore(int x, int y, int width, int height, swf.B
}

// optimization especially for content on drawable
protected override void OnBackColorChanged( EventArgs e )
protected override void OnBackColorChanged(EventArgs e)
{
SetStyle
( swf.ControlStyles.AllPaintingInWmPaint
(swf.ControlStyles.AllPaintingInWmPaint
| swf.ControlStyles.DoubleBuffer
, BackColor.A != 255 );
base.OnBackColorChanged( e );
, BackColor.A != 255);
base.OnBackColorChanged(e);
}
protected override void OnParentBackColorChanged( EventArgs e )
protected override void OnParentBackColorChanged(EventArgs e)
{
SetStyle
( swf.ControlStyles.AllPaintingInWmPaint
(swf.ControlStyles.AllPaintingInWmPaint
| swf.ControlStyles.DoubleBuffer
, BackColor.A != 255 );
base.OnParentBackColorChanged( e );
, BackColor.A != 255);
base.OnParentBackColorChanged(e);
}
}

Expand Down Expand Up @@ -172,7 +172,7 @@ public void Add(Control child, int x, int y)
{
if (Widget.Loaded)
SuspendLayout();

var old = views[x, y];
if (old != null)
old.GetContainerControl().Parent = null;
Expand Down Expand Up @@ -217,7 +217,7 @@ public void Move(Control child, int x, int y)

public override void OnLoad(EventArgs e)
{
SetMinimumSize(useCache: true); // when created during pre-load, we need this to ensure the scale is set on the children properly
SetMinimumSize(useCache: true); // when created during pre-load, we need this to ensure the scale is set on the children properly
base.OnLoad(e);
FillEmptyCells();
}
Expand Down Expand Up @@ -263,14 +263,12 @@ void FillEmptyCells()
{
for (int x = 1; x < views.GetLength(0); x++)
{
var ctl = Control.GetControlFromPosition(x, 0);
if (ctl == null)
if (Control.GetControlFromPosition(x, 0) == null && views[x, 0] == null)
Control.Controls.Add(CreateEmptyCell(x, 0), x, 0);
}
for (int y = 0; y < views.GetLength(1); y++)
{
var ctl = Control.GetControlFromPosition(0, y);
if (ctl == null)
if (Control.GetControlFromPosition(0, y) == null && views[0, y] == null)
Control.Controls.Add(CreateEmptyCell(0, y), 0, y);
}
}
Expand All @@ -283,6 +281,7 @@ public void Remove(Control child)
var pos = Control.GetCellPosition(childControl);
views[pos.Column, pos.Row] = null;
childControl.Parent = null;
SetEmptyCell(pos.Column, pos.Row);
}
}

Expand Down

0 comments on commit 5e91c71

Please sign in to comment.