共用方式為


DataRepeater.LayoutStyleChanged 事件

更新:2007 年 11 月

發生於 LayoutStyle 屬性值變更時。

命名空間:  Microsoft.VisualBasic.PowerPacks
組件:  Microsoft.VisualBasic.PowerPacks.Vs (在 Microsoft.VisualBasic.PowerPacks.Vs.dll 中)

語法

Public Event LayoutStyleChanged As EventHandler

Dim instance As DataRepeater
Dim handler As EventHandler

AddHandler instance.LayoutStyleChanged, handler
public event EventHandler LayoutStyleChanged
public:
 event EventHandler^ LayoutStyleChanged {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
JScript 不支援事件。

備註

DataRepeater 控制項的 LayoutStyle 屬性會決定是以垂直格式還是水平格式顯示 DataRepeater 項目。當這個屬性變更時,您可以使用 LayoutStyleChanged 事件處理常式重新排列 ItemTemplate 中的子控制項,以配合新的配置。

如需如何處理事件的詳細資訊,請參閱使用事件

範例

下列範例顯示如何在事件處理常式中回應 LayoutStyleChanged 事件。這個範例要求您的表單必須有一個名為 DataRepeater1 的 DataRepeater 控制項,而且這個控制項必須包含兩個名為 TextBox1 和 TextBox2 的 TextBox 控制項。

Private Sub DataRepeater1_LayoutStyleChanged(ByVal sender As Object, _
 ByVal e As System.EventArgs) Handles DataRepeater1.LayoutStyleChanged
    ' Call a method to re-initialize the template.
    DataRepeater1.BeginResetItemTemplate()
    If DataRepeater1.LayoutStyle = _
     PowerPacks.DataRepeaterLayoutStyles.Vertical Then
        ' Change the height of the template and rearrange the controls.
        DataRepeater1.ItemTemplate.Height = 150
        DataRepeater1.ItemTemplate.Controls(TextBox1.Name).Location = _
         New Point(20, 40)
        DataRepeater1.ItemTemplate.Controls(TextBox2.Name).Location = _
         New Point(150, 40)
    Else
        ' Change the width of the template and rearrange the controls.
        DataRepeater1.ItemTemplate.Width = 150
        DataRepeater1.ItemTemplate.Controls(TextBox1.Name).Location = _
         New Point(40, 20)
        DataRepeater1.ItemTemplate.Controls(TextBox2.Name).Location = _
         New Point(40, 150)
    End If
    ' Apply the changes to the template.
    DataRepeater1.EndResetItemTemplate()
End Sub
private void dataRepeater1_LayoutStyleChanged_1(object sender, EventArgs e)
{
    // Call a method to re-initialize the template.
    dataRepeater1.BeginResetItemTemplate();
    if (dataRepeater1.LayoutStyle == DataRepeaterLayoutStyles.Vertical)
    // Change the height of the template and rearrange the controls.
    {
        dataRepeater1.ItemTemplate.Height = 150;
        dataRepeater1.ItemTemplate.Controls["TextBox1"].Location = new Point(20, 40);
        dataRepeater1.ItemTemplate.Controls["TextBox2"].Location = new Point(150, 40);
    }
    else
    {
        // Change the width of the template and rearrange the controls.
        dataRepeater1.ItemTemplate.Width = 150;
        dataRepeater1.ItemTemplate.Controls["TextBox1"].Location = new Point(40, 20);
        dataRepeater1.ItemTemplate.Controls["TextBox2"].Location = new Point(40, 150);
    }
    // Apply the changes to the template.
    dataRepeater1.EndResetItemTemplate();
}

使用權限

請參閱

參考

DataRepeater 類別

DataRepeater 成員

Microsoft.VisualBasic.PowerPacks 命名空間

LayoutStyle

其他資源

DataRepeater 控制項簡介 (Visual Studio)

HOW TO:變更 DataRepeater 控制項的配置 (Visual Studio)