我试图在Eto表单中做一个动态布局,它有两列被分成50/50的列。看起来默认的行为是给一行中的最后一个控件留出剩余空间。然后,我创建了一个事件处理程序,它将控件的大小调整为画布宽度的1/2。这是可行的(如图所示),但在调整窗口大小时速度较慢。它看起来像是重绘滞后了几毫秒,因此画布的部分是黑色的。在ETO中有没有更好的方法来做到这一点?

我将我的代码粘贴到下面。这个窗口有大约20个控件,为了清楚起见,我在下面的代码中将它们减少到了2个。
public class MyLayout : DynamicLayout
{
public CheckBox PeopleIsOn = new CheckBox() { Text = "On/Off" };
public Label PeopleLabel = new Label { Text = "People" };
public MyLayout(){
PeopleIsOn.SizeChanged += (s, e) =>
{
PeopleLabel.Width = Width / 2;
Invalidate();
};
this.BeginVertical();
this.BeginHorizontal();
this.Add(PeopleLabel);
this.Add(PeopleIsOn);
this.EndHorizontal();
this.EndVertical();
}
}在WPF中,这可以通过<ColumnDefinition Width="*" />很容易地实现。在Eto.Forms中有没有类似的东西?
发布于 2018-11-12 18:03:44
我试着用TableLayout代替DynamicLayout,它对我很有效。
public class MyLayout : TableLayout
{
public CheckBox PeopleIsOn = new CheckBox() { Text = "On/Off" };
public Label PeopleLabel = new Label { Text = "People" };
public CheckBox OtherIsOn = new CheckBox() { Text = "On/Off" };
public Label OtherLabel = new Label { Text = "Other" };
public MyLayout()
{
this.Rows.Add(new TableRow(
new TableCell(PeopleLabel, true), // the true argument of TableCell is important in the cells of the first row
new TableCell(PeopleIsOn, true)
));
this.Rows.Add(new TableRow(
OtherLabel, // from second row the parameter is no longer needed
OtherIsOn
));
}
}https://stackoverflow.com/questions/51684470
复制相似问题