代码之家  ›  专栏  ›  技术社区  ›  timkado

ETO表格中的缓慢动态布局

  •  0
  • timkado  · 技术社区  · 6 年前

    我正在尝试在ETO表单中创建一个动态布局,该表单有两列,分别为50/50。 似乎默认行为是为一行中的最后一个控件提供剩余空间。然后我创建了一个事件处理程序,它将控件的大小调整为画布宽度的1/2。这可以工作(见图),但在调整窗口大小时速度很慢。看起来重绘滞后了几毫秒,因此画布的某些部分是黑色的。 在ETO有更好的方法吗?

    Two columns of controls

    我在下面粘贴我的代码。窗口中有大约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表格中有等价的吗?

    1 回复  |  直到 6 年前
        1
  •  0
  •   user757095    6 年前

    我试过用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
            ));
        }
    }