ListViewItem.Position 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定 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 的 ListViewItem 屬性。 若要執行此範例,請將下列程式碼貼到 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 的 屬性從 SmallIcon 、 LargeIcon 或 檢視變更為 List 或 TileDetails 時 View ,屬性會自動變更。 ListView當 位於 、 LargeIcon 或 Tile 檢視中 SmallIcon 時,設定 Position 專案的 屬性會導致 重新排列 中 ListView 所包含的其他專案。