SearchDirectionHint Enum
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menyediakan petunjuk arah tempat untuk ListViewItemmencari .
public enum class SearchDirectionHint
public enum SearchDirectionHint
type SearchDirectionHint =
Public Enum SearchDirectionHint
- Warisan
Bidang
Down | 40 | Di bawah item saat ini. |
Left | 37 | Di sebelah kiri item saat ini. |
Right | 39 | Di sebelah kanan item saat ini. |
Up | 38 | Di atas item saat ini. |
Contoh
Contoh kode berikut menunjukkan cara menggunakan SearchDirectionHint enumerasi. Untuk menjalankan contoh ini, tempelkan kode berikut ke dalam Formulir Windows dan panggil InitializeLocationSearchListView
dari konstruktor formulir atau Load metode penanganan peristiwa.
ListView^ iconListView;
TextBox^ previousItemBox;
private:
void InitializeLocationSearchListView()
{
previousItemBox = gcnew TextBox();
iconListView = gcnew ListView();
previousItemBox->Location = Point(150, 20);
// Create an image list for the icon ListView.
iconListView->SmallImageList = gcnew ImageList();
// Add an image to the ListView small icon list.
iconListView->SmallImageList->Images->Add(
gcnew Bitmap(Control::typeid, "Edit.bmp"));
// Set the view to small icon and add some items with the image
// in the image list.
iconListView->View = View::SmallIcon;
iconListView->Items->AddRange(gcnew array<ListViewItem^>{
gcnew ListViewItem("Amy Alberts", 0),
gcnew ListViewItem("Amy Recker", 0),
gcnew ListViewItem("Erin Hagens", 0),
gcnew ListViewItem("Barry Johnson", 0),
gcnew ListViewItem("Jay Hamlin", 0),
gcnew ListViewItem("Brian Valentine", 0),
gcnew ListViewItem("Brian Welker", 0),
gcnew ListViewItem("Daniel Weisman", 0) });
this->Controls->Add(iconListView);
this->Controls->Add(previousItemBox);
// Handle the MouseDown event to capture user input.
iconListView->MouseDown += gcnew MouseEventHandler(
this, &Form1::iconListView_MouseDown);
}
void iconListView_MouseDown(Object^ sender, MouseEventArgs^ e)
{
// Find the next item up from where the user clicked.
ListViewItem^ foundItem = iconListView->FindNearestItem(
SearchDirectionHint::Up, e->X, e->Y);
// Display the results in a textbox..
if (foundItem != nullptr)
{
previousItemBox->Text = foundItem->Text;
}
else
{
previousItemBox->Text = "No item found";
}
}
ListView iconListView = new ListView();
TextBox previousItemBox = new TextBox();
private void InitializeLocationSearchListView()
{
previousItemBox.Location = new Point(150, 20);
// Create an image list for the icon ListView.
iconListView.LargeImageList = new ImageList();
iconListView.Height = 400;
// Add an image to the ListView large icon list.
iconListView.LargeImageList.Images.Add(
new Bitmap(typeof(Control), "Edit.bmp"));
// Set the view to large icon and add some items with the image
// in the image list.
iconListView.View = View.LargeIcon;
iconListView.Items.AddRange(new ListViewItem[]{
new ListViewItem("Amy Alberts", 0),
new ListViewItem("Amy Recker", 0),
new ListViewItem("Erin Hagens", 0),
new ListViewItem("Barry Johnson", 0),
new ListViewItem("Jay Hamlin", 0),
new ListViewItem("Brian Valentine", 0),
new ListViewItem("Brian Welker", 0),
new ListViewItem("Daniel Weisman", 0) });
this.Controls.Add(iconListView);
this.Controls.Add(previousItemBox);
// Handle the MouseDown event to capture user input.
iconListView.MouseDown +=
new MouseEventHandler(iconListView_MouseDown);
//iconListView.MouseWheel += new MouseEventHandler(iconListView_MouseWheel);
}
void iconListView_MouseDown(object sender, MouseEventArgs e)
{
// Find the an item above where the user clicked.
ListViewItem foundItem =
iconListView.FindNearestItem(SearchDirectionHint.Up, e.X, e.Y);
// Display the results in a textbox..
if (foundItem != null)
previousItemBox.Text = foundItem.Text;
else
previousItemBox.Text = "No item found";
}
Private WithEvents iconListView As New ListView()
Private previousItemBox As New TextBox()
Private Sub InitializeLocationSearchListView()
previousItemBox.Location = New Point(150, 20)
' Create an image list for the icon ListView.
iconListView.LargeImageList = New ImageList()
' Add an image to the ListView large icon list.
iconListView.LargeImageList.Images.Add(New Bitmap(GetType(Control), "Edit.bmp"))
' Set the view to large icon and add some items with the image
' in the image list.
iconListView.View = View.SmallIcon
iconListView.Items.AddRange(New ListViewItem() { _
New ListViewItem("Amy Alberts", 0), _
New ListViewItem("Amy Recker", 0), _
New ListViewItem("Erin Hagens", 0), _
New ListViewItem("Barry Johnson", 0), _
New ListViewItem("Jay Hamlin", 0), _
New ListViewItem("Brian Valentine", 0), _
New ListViewItem("Brian Welker", 0), _
New ListViewItem("Daniel Weisman", 0)})
Me.Controls.Add(iconListView)
Me.Controls.Add(previousItemBox)
End Sub
Sub iconListView_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) _
Handles iconListView.MouseDown
' Find the next item up from where the user clicked.
Dim foundItem As ListViewItem = _
iconListView.FindNearestItem(SearchDirectionHint.Up, e.X, e.Y)
' Display the results in a textbox.
If (foundItem IsNot Nothing) Then
previousItemBox.Text = foundItem.Text
Else
previousItemBox.Text = "No item found"
End If
End Sub
Keterangan
Enumerasi ini digunakan oleh FindNearestItem metode di ListView kelas dan ListViewItem , serta oleh SearchForVirtualItemEventArgs kelas . Mengidentifikasi item terdekat dalam ListView kontrol dapat bervariasi tergantung pada sistem operasi yang dijalankan aplikasi; oleh karena itu, arah pencarian adalah petunjuk, dan bukan jaminan mutlak hasil.