Bagikan melalui


Cara: Tentukan Apakah Hyperlink Digaris bawahi

Objek Hyperlink adalah elemen konten alur tingkat sebaris yang memungkinkan Anda menghosting hyperlink dalam konten alur. Secara default, Hyperlink menggunakan TextDecoration objek untuk menampilkan garis bawah. TextDecoration objek dapat berkinerja intensif untuk membuat instans, terutama jika Anda memiliki banyak Hyperlink objek. Jika Anda menggunakan elemen secara Hyperlink ekstensif, Anda mungkin ingin mempertimbangkan untuk menampilkan garis bawah hanya saat memicu peristiwa, seperti MouseEnter peristiwa.

Dalam contoh berikut, garis bawah untuk tautan "MSN Saya" bersifat dinamis, yaitu hanya muncul ketika MouseEnter peristiwa dipicu.

Hyperlinks displaying TextDecorations

Contoh

Sampel markup berikut menunjukkan yang Hyperlink ditentukan dengan dan tanpa garis bawah:

<!-- Hyperlink with default underline. -->
<Hyperlink NavigateUri="http://www.msn.com">
  MSN Home
</Hyperlink>

<Run Text=" | " />

<!-- Hyperlink with no underline. -->
<Hyperlink Name="myHyperlink" TextDecorations="None"
           MouseEnter="OnMouseEnter"
           MouseLeave="OnMouseLeave"
           NavigateUri="http://www.msn.com">
  My MSN
</Hyperlink>

Sampel kode berikut menunjukkan cara membuat garis bawah untuk Hyperlink peristiwa MouseEnter , dan menghapusnya pada MouseLeave peristiwa.

// Display the underline on only the MouseEnter event.
private void OnMouseEnter(object sender, EventArgs e)
{
    myHyperlink.TextDecorations = TextDecorations.Underline;
}

// Remove the underline on the MouseLeave event.
private void OnMouseLeave(object sender, EventArgs e)
{
    myHyperlink.TextDecorations = null;
}
' Display the underline on only the MouseEnter event.
Private Overloads Sub OnMouseEnter(ByVal sender As Object, ByVal e As EventArgs)
    myHyperlink.TextDecorations = TextDecorations.Underline
End Sub

' Remove the underline on the MouseLeave event.
Private Overloads Sub OnMouseLeave(ByVal sender As Object, ByVal e As EventArgs)
    myHyperlink.TextDecorations = Nothing
End Sub

Baca juga