RichTextBox.SelectionProtected Properti
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.
Mendapatkan atau menetapkan nilai yang menunjukkan apakah pilihan teks saat ini dilindungi.
public:
property bool SelectionProtected { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool SelectionProtected { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.SelectionProtected : bool with get, set
Public Property SelectionProtected As Boolean
Nilai Properti
true
jika pilihan saat ini mencegah perubahan apa pun pada isinya; jika tidak, false
. Default adalah false
.
- Atribut
Contoh
Contoh kode berikut menunjukkan cara menentukan teks yang RichTextBox dilindungi dalam menggunakan SelectionProtected properti . Contoh ini mengharuskan RichTextBox kontrol, bernama richTextBox1
, telah ditambahkan ke formulir dan bahwa kontrol memiliki teks yang RichTextBox ditambahkan ke dalamnya yang berisi kata "RichTextBox."
private:
void ProtectMySelectedText()
{
// Determine if the selected text in the control contains the word "RichTextBox".
if ( !richTextBox1->SelectedText->Equals( "RichTextBox" ) )
{
// Search for the word RichTextBox in the control.
if ( richTextBox1->Find( "RichTextBox", RichTextBoxFinds::WholeWord ) == -1 )
{
//Alert the user that the word was not foun and return.
MessageBox::Show( "The text \"RichTextBox\" was not found!" );
return;
}
}
// Protect the selected text in the control from being altered.
richTextBox1->SelectionProtected = true;
}
private void ProtectMySelectedText()
{
// Determine if the selected text in the control contains the word "RichTextBox".
if(richTextBox1.SelectedText != "RichTextBox")
{
// Search for the word RichTextBox in the control.
if(richTextBox1.Find("RichTextBox",RichTextBoxFinds.WholeWord)== -1)
{
//Alert the user that the word was not foun and return.
MessageBox.Show("The text \"RichTextBox\" was not found!");
return;
}
}
// Protect the selected text in the control from being altered.
richTextBox1.SelectionProtected = true;
}
Private Sub ProtectMySelectedText()
' Determine if the selected text in the control contains the word "RichTextBox".
If richTextBox1.SelectedText <> "RichTextBox" Then
' Search for the word RichTextBox in the control.
If richTextBox1.Find("RichTextBox", RichTextBoxFinds.WholeWord) = -1 Then
'Alert the user that the word was not foun and return.
MessageBox.Show("The text ""RichTextBox"" was not found!")
Return
End If
End If
' Protect the selected text in the control from being altered.
richTextBox1.SelectionProtected = True
End Sub
Keterangan
Jika saat ini tidak ada teks yang dipilih, pengaturan perlindungan diterapkan ke paragraf tempat titik penyisipan muncul dan ke semua teks yang diketik ke dalam kontrol setelah titik penyisipan. Pengaturan perlindungan berlaku hingga properti diubah ke nilai yang berbeda atau hingga titik penyisipan dipindahkan ke paragraf lain dalam kontrol.
Jika teks dipilih dalam kontrol, teks yang dipilih dan teks apa pun yang dimasukkan setelah pilihan teks akan memiliki nilai properti ini yang diterapkan padanya. Anda dapat menggunakan properti ini untuk mencegah pengguna mengubah bagian teks dalam kontrol.
Jika properti ini diatur ke true
, Protected peristiwa dinaikkan ketika pengguna mencoba mengubah pilihan teks saat ini.
Catatan
Properti ini hanya akan kembali true
jika seluruh pilihan dalam kontrol berisi isi terproteksi.
Berlaku untuk
Lihat juga
Saran dan Komentar
https://aka.ms/ContentUserFeedback.
Segera hadir: Sepanjang tahun 2024 kami akan menghentikan penggunaan GitHub Issues sebagai mekanisme umpan balik untuk konten dan menggantinya dengan sistem umpan balik baru. Untuk mengetahui informasi selengkapnya, lihat:Kirim dan lihat umpan balik untuk