放置Telerik Winforms StackLayoutPanel在表单上

时间:2009-04-01 03:28:23

标签: c# winforms telerik

在表单上放置RadElement实例的推荐方法是什么?

以下是我的表单构造函数中的代码。我的目标是,如果大小足够小,表单将显示滚动条。 #else下的代码涉及标准的Winforms控件,并且工作正常。 #if Telerik下的代码是等效的,但不起作用,因为我无法将StackLayoutPanel添加到窗体的Controls集合中。如果有人可以使用下面的#if Telerik代码的修改版本进行回复,那么会将StackLayoutPanel置于表单上,以便在表单大小小于面板时显示表单的滚动条。

    AutoScroll = true;
#if Telerik
    StackLayoutPanel panel = new StackLayoutPanel();
    panel.Orientation = Orientation.Vertical;
    panel.AutoSize = true;
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    panel.Children.Add(new RadButtonElement());
    Controls.Add(panel);
#else
    FlowLayoutPanel panel = new FlowLayoutPanel();
    panel.FlowDirection = FlowDirection.TopDown;
    panel.AutoSize = true;
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    panel.Controls.Add(new Button());
    Controls.Add(panel);
#endif

1 个答案:

答案 0 :(得分:1)

您可以先在面板控件中添加StackLayoutPanel:

var panelControl = new RadPanel();
panelControl.PanelElement.Children.Add(panel);
Controls.Add(panelControl);