FormattedText.SetFontWeight 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
設定 FormattedText 物件的字型粗細。
多載
SetFontWeight(FontWeight, Int32, Int32) |
變更 FontWeight 物件內所指定文字的 FormattedText。 |
SetFontWeight(FontWeight) |
設定 FormattedText 物件中整個字元集的字型粗細。 |
SetFontWeight(FontWeight, Int32, Int32)
變更 FontWeight 物件內所指定文字的 FormattedText。
public:
void SetFontWeight(System::Windows::FontWeight weight, int startIndex, int count);
public void SetFontWeight (System.Windows.FontWeight weight, int startIndex, int count);
member this.SetFontWeight : System.Windows.FontWeight * int * int -> unit
Public Sub SetFontWeight (weight As FontWeight, startIndex As Integer, count As Integer)
參數
- weight
- FontWeight
用於文字格式設定的字型粗細。
- startIndex
- Int32
要套用字型粗細之初始字元的起始索引。
- count
- Int32
要套用字型粗細的字元數目。
範例
下列範例會建立 物件,然後將數個 FormattedText 格式樣式套用至文字,包括 SetFontWeight 。
protected override void OnRender(DrawingContext drawingContext)
{
string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
// Create the initial formatted text string.
FormattedText formattedText = new FormattedText(
testString,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
32,
Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300;
formattedText.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
formattedText.SetFontWeight(FontWeights.Bold, 6, 11);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28);
// Draw the formatted text string to the DrawingContext of the control.
drawingContext.DrawText(formattedText, new Point(10, 0));
}
Protected Overrides Sub OnRender(ByVal drawingContext As DrawingContext)
Dim testString As String = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor"
' Create the initial formatted text string.
Dim formattedText As New FormattedText(testString, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Verdana"), 32, Brushes.Black)
' Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300
formattedText.MaxTextHeight = 240
' Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
' The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5)
' Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
formattedText.SetFontWeight(FontWeights.Bold, 6, 11)
' Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(New LinearGradientBrush(Colors.Orange, Colors.Teal, 90.0), 6, 11)
' Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28)
' Draw the formatted text string to the DrawingContext of the control.
drawingContext.DrawText(formattedText, New Point(10, 0))
End Sub
備註
FontWeight 支援型別轉換行為,讓 類別的 FontWeights 靜態值可用來初始化 FontWeight 和填滿類型的參數 FontWeight 。
適用於
SetFontWeight(FontWeight)
設定 FormattedText 物件中整個字元集的字型粗細。
public:
void SetFontWeight(System::Windows::FontWeight weight);
public void SetFontWeight (System.Windows.FontWeight weight);
member this.SetFontWeight : System.Windows.FontWeight -> unit
Public Sub SetFontWeight (weight As FontWeight)
參數
- weight
- FontWeight
用於文字格式設定的 FontWeight。
備註
FontWeight 支援型別轉換行為,讓 類別的 FontWeights 靜態值可用來初始化 FontWeight 和填滿類型的參數 FontWeight 。