首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ETO表单中缓慢的动态布局

ETO表单中缓慢的动态布局
EN

Stack Overflow用户
提问于 2018-08-04 17:59:38
回答 1查看 266关注 0票数 0

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

我将我的代码粘贴到下面。这个窗口有大约20个控件,为了清楚起见,我在下面的代码中将它们减少到了2个。

代码语言:javascript
复制
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中有没有类似的东西?

EN

回答 1

Stack Overflow用户

发布于 2018-11-12 18:03:44

我试着用TableLayout代替DynamicLayout,它对我很有效。

代码语言:javascript
复制
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
        ));
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51684470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档