共用方式為


ListViewItem.IndentCount 屬性

定義

取得或設定用以縮排 ListViewItem 之小型影像寬度的數目。

public:
 property int IndentCount { int get(); void set(int value); };
public int IndentCount { get; set; }
member this.IndentCount : int with get, set
Public Property IndentCount As Integer

屬性值

用以縮排 ListViewItem 之小型影像寬度的數字。

例外狀況

設定 IndentCount 時,指定的數字小於 0。

範例

下列程式碼範例示範如何設定 IndentCount 屬性。 若要執行此範例,請將下列程式碼貼到 Windows Form 中,並從表單的建構函式或 Load 事件處理方法呼叫 InitializeIndentedListViewItems 方法。

ListView indentedListView;

private void InitializeIndentedListViewItems()
{
    indentedListView = new ListView();
    indentedListView.Width = 200;

    // View must be set to Details to use IndentCount.
    indentedListView.View = View.Details;
    indentedListView.Columns.Add("Indented Items", 150);
   
    // Create an image list and add an image.
    ImageList list = new ImageList();
    list.Images.Add(new Bitmap(typeof(Button), "Button.bmp"));

    // SmallImageList must be set when using IndentCount.
    indentedListView.SmallImageList = list;

    ListViewItem item1 = new ListViewItem("Click", 0);
    item1.IndentCount = 1;
    ListViewItem item2 = new ListViewItem("OK", 0);
    item2.IndentCount = 2;
    ListViewItem item3 = new ListViewItem("Cancel", 0);
    item3.IndentCount = 3;
    indentedListView.Items.AddRange(new ListViewItem[] { item1, item2, item3 });

    // Add the controls to the form.
    this.Controls.Add(indentedListView);
}
Private indentedListView As ListView


Private Sub InitializeIndentedListViewItems() 
    indentedListView = New ListView()
    indentedListView.Width = 200
    
    ' View must be set to Details to use IndentCount.
    indentedListView.View = View.Details
    indentedListView.Columns.Add("Indented Items", 150)
    
    ' Create an image list and add an image.
    Dim list As New ImageList()
    list.Images.Add(New Bitmap(GetType(Button), "Button.bmp"))
    
    ' SmallImageList must be set when using IndentCount.
    indentedListView.SmallImageList = list
    
    Dim item1 As New ListViewItem("Click", 0)
    item1.IndentCount = 1
    Dim item2 As New ListViewItem("OK", 0)
    item2.IndentCount = 2
    Dim item3 As New ListViewItem("Cancel", 0)
    item3.IndentCount = 3
    indentedListView.Items.AddRange(New ListViewItem() {item1, item2, item3})
    
    ' Add the controls to the form.
    Me.Controls.Add(indentedListView)

End Sub

備註

只有當包含 ListView 的 屬性設定為 Details ,且 SmallImageList 的 屬性已設定時 View ,才能使用 屬性 ListViewIndentCount

適用於