TextBoxBase.Select(Int32, Int32) Metode
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.
Memilih rentang teks dalam kotak teks.
public:
void Select(int start, int length);
public void Select(int start, int length);
override this.Select : int * int -> unit
Public Sub Select (start As Integer, length As Integer)
Parameter
- start
- Int32
Posisi karakter pertama dalam pilihan teks saat ini dalam kotak teks.
- length
- Int32
Jumlah karakter yang akan dipilih.
Pengecualian
Nilai start parameter kurang dari nol.
Contoh
Contoh kode berikut menggunakan TextBox, kelas turunan, untuk mencari konten kontrol untuk instans kata "rubah". Jika ditemukan, kode memilih kata dalam kontrol menggunakan Select metode . Contoh ini mengharuskan nama TextBoxtextBox1 telah dibuat dan propertinya Text berisi kalimat "Rubah coklat cepat melompati anjing malas."
public:
void SelectMyString()
{
// Create a string to search for the word "fox".
String^ searchString = "fox";
// Determine the starting location of the word "fox".
int index = textBox1->Text->IndexOf( searchString, 16, 3 );
// Determine if the word has been found and select it if it was.
if ( index != -1 )
{
// Select the string using the index and the length of the string.
textBox1->Select( index,searchString->Length );
}
}
public void SelectMyString()
{
// Create a string to search for the word "fox".
String searchString = "fox";
// Determine the starting location of the word "fox".
int index = textBox1.Text.IndexOf(searchString, 16, 3);
// Determine if the word has been found and select it if it was.
if (index != -1)
{
// Select the string using the index and the length of the string.
textBox1.Select(index, searchString.Length);
}
}
Public Sub SelectMyString()
' Create a string to search for the word "fox".
Dim searchString As String = "fox"
' Determine the starting location of the word "fox".
Dim index As Integer = textBox1.Text.IndexOf(searchString, 16, 3)
' Determine if the word has been found and select it if it was.
If index <> - 1 Then
' Select the string using the index and the length of the string.
textBox1.Select(index, searchString.Length)
End If
End Sub
Keterangan
Jika Anda ingin mengatur posisi awal ke karakter pertama dalam teks kontrol, atur start parameter ke 0. Anda dapat menggunakan metode ini untuk memilih substring teks, seperti saat mencari teks kontrol dan mengganti informasi.
Nota
Anda dapat memindahkan tanda sisipan secara terprogram dalam kotak teks dengan mengatur start parameter ke posisi dalam kotak teks tempat Anda ingin tanda sisipan berpindah dan mengatur length parameter ke nilai nol (0). Kotak teks harus memiliki fokus agar tanda sisipan dipindahkan.
Nota
Jika metode ini dipanggil tanpa parameter apa pun, metode alternatif digunakan. Metode alternatif ini mewarisi dari Control kelas . Saat dipanggil, ia mengatur fokus input ke kontrol dan memilih konten kontrol. Untuk informasi selengkapnya, lihat metode Control.Select.