閱讀英文版本

分享方式:


TextDecorationLocation 列舉

定義

指定 TextDecoration 物件的垂直位置。

C#
public enum TextDecorationLocation
繼承
TextDecorationLocation

欄位

名稱 Description
Baseline 3

基準線的垂直位置。

OverLine 1

頂線的垂直位置。

Strikethrough 2

刪除線的垂直位置。

Underline 0

底線的垂直位置。 這是預設值。

範例

下列範例會建立底線文字裝飾,並使用畫筆的純色筆刷。

C#
// Use a Red pen for the underline text decoration.
private void SetRedUnderline()
{
    // Create an underline text decoration. Default is underline.
    TextDecoration myUnderline = new TextDecoration();

    // Create a solid color brush pen for the text decoration.
    myUnderline.Pen = new Pen(Brushes.Red, 1);
    myUnderline.PenThicknessUnit = TextDecorationUnit.FontRecommended;

    // Set the underline decoration to a TextDecorationCollection and add it to the text block.
    TextDecorationCollection myCollection = new TextDecorationCollection();
    myCollection.Add(myUnderline);
    TextBlock2.TextDecorations = myCollection;
}
XAML
<!-- Use a Red pen for the underline text decoration -->
<TextBlock
  FontSize="36" >
  jumps over
  <TextBlock.TextDecorations>
    <TextDecorationCollection>
      <TextDecoration 
        PenThicknessUnit="FontRecommended">
        <TextDecoration.Pen>
          <Pen Brush="Red" Thickness="1" />
        </TextDecoration.Pen>
      </TextDecoration>
    </TextDecorationCollection>
  </TextBlock.TextDecorations>
</TextBlock>

備註

文字裝飾有四種類型:基準、超線、刪除線和底線。 下列範例顯示文字裝飾相對於文字的位置。

文字裝飾位置圖表
文字裝飾類型

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9