共用方式為


ListViewItem.Position 屬性

定義

取得或設定 ListViewItem 左上角的位置。

public:
 property System::Drawing::Point Position { System::Drawing::Point get(); void set(System::Drawing::Point value); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Point Position { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.Position : System.Drawing.Point with get, set
Public Property Position As Point

屬性值

位於 Point 左上角的 ListViewItem

屬性

例外狀況

Position 是在包含的 ListView 處於虛擬模式時設定的。

範例

下列程式碼範例示範如何使用 PositionListViewItem 屬性。 若要執行此範例,請將下列程式碼貼到 Windows Form 中,然後從表單 Load 的事件處理方法呼叫 InitializePositionedListViewItems 。 按一下按鈕以查看專案重新置放。

private ListView positionListView;
private ListViewItem moveItem;
private Button button1;

private void InitializePositionedListViewItems()
{
    // Set some basic properties on the ListView and button.
    positionListView = new ListView();
    positionListView.Height = 200;
    button1 = new Button();
    button1.Location = new Point(160, 30);
    button1.AutoSize = true;
    button1.Text = "Click to reposition";
    button1.Click += new System.EventHandler(button1_Click);

    // View must be set to icon view to use the Position property.
    positionListView.View = View.LargeIcon;
  
    // Create the items and add them to the ListView.
    ListViewItem item1 = new ListViewItem("Click");
    ListViewItem item2 = new ListViewItem("OK");
    moveItem = new ListViewItem("Move");
    positionListView.Items.AddRange(new ListViewItem[] 
        { item1, item2, moveItem });

    // Add the controls to the form.
    this.Controls.Add(positionListView);
    this.Controls.Add(button1);
}

private void button1_Click(object sender, EventArgs e)
{
    moveItem.Position = new Point(30, 30);
}
Private positionListView As ListView
Private moveItem As ListViewItem
Private WithEvents button1 As Button


Private Sub InitializePositionedListViewItems() 
    ' Set some basic properties on the ListView and button.
    positionListView = New ListView()
    positionListView.Height = 200
    button1 = New Button()
    button1.Location = New Point(160, 30)
    button1.AutoSize = True
    button1.Text = "Click to reposition"

    ' View must be set to icon view to use the Position property.
    positionListView.View = View.LargeIcon
    
    ' Create the items and add them to the ListView.
    Dim item1 As New ListViewItem("Click")
    Dim item2 As New ListViewItem("OK")
    moveItem = New ListViewItem("Move")
    positionListView.Items.AddRange(New ListViewItem() _
        {item1, item2, moveItem})
    
    ' Add the controls to the form.
    Me.Controls.Add(positionListView)
    Me.Controls.Add(button1)

End Sub

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
    moveItem.Position = New Point(30, 30)
End Sub

備註

屬性 Position 應該在 建構 和 包含 ListView 之後 ListViewItem 設定。 Position當 包含 ListView 位於 或 List 檢視中 Details 時變更 屬性,不會影響專案的位置。 此外, Position 當 包含 ListView 的 屬性從 SmallIconLargeIcon 或 檢視變更為 ListTileDetailsView ,屬性會自動變更。 ListView當 位於 、 LargeIconTile 檢視中 SmallIcon 時,設定 Position 專案的 屬性會導致 重新排列 中 ListView 所包含的其他專案。

適用於

另請參閱