共用方式為


如何:指定超連結是否要加上底線

物件 Hyperlink 是內嵌層級的流程內容專案,可讓您在流程內容中裝載超連結。 根據預設, Hyperlink 會使用 TextDecoration 物件來顯示底線。 TextDecoration 物件可能需要大量效能才能具現化,特別是如果您有許多 Hyperlink 物件。 如果您廣泛使用 Hyperlink 元素,您可能只想在觸發事件時顯示底線,例如 MouseEnter 事件。

在下列範例中,「My MSN」 連結的底線是動態的,也就是說,它只會在觸發事件時 MouseEnter 出現。

Hyperlinks displaying TextDecorations

範例

下列標記範例顯示 Hyperlink 使用 和 沒有底線定義的 :

<!-- 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>

下列程式碼範例示範如何為 HyperlinkMouseEnter 事件建立 底線,並在 事件上 MouseLeave 移除它。

// 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

另請參閱