日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

WPF 文本呈现(2)

發(fā)布時間:2025/5/22 asp.net 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 WPF 文本呈现(2) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?

文本輸出規(guī)則

比如輸出Hello,可以多種輸出方法.如下

  • Hello
  • He llo
  • H e l l o
  • 當都遵循一個原則,字符將從左到右輸出,

    如H(0,1),ell(1,3),o(4,1) 表示從索引值輸出多少個字符.這個過程將一直持續(xù)下去直到段落結(jié)束為止

    輸出多彩文字

    public override TextRun GetTextRun(int textSourceCharacterIndex) {//typeof(Brushes).GetProperties()[0].GetValue()if (textSourceCharacterIndex >= _text.Length){return new TextEndOfParagraph(1);}_currentRendering.TextColor = brushs[textSourceCharacterIndex] as SolidColorBrush;// Create TextCharacters using the current font rendering properties.if (textSourceCharacterIndex < _text.Length){return new TextCharacters(_text,textSourceCharacterIndex,1,new GenericTextRunProperties(_currentRendering));}// Return an end-of-paragraph if no more text source.return new TextEndOfParagraph(1); }

    輸出結(jié)果

    每次從當前索引輸出一個字符,每次更改字符屬性的顏色

    更改大小

    每隔三次字符輸出Winow單詞

    _currentRendering.TextColor = brushs[textSourceCharacterIndex] as SolidColorBrush;_currentRendering.FontSize = textSourceCharacterIndex*12+12;return new TextCharacters(_text,textSourceCharacterIndex,3,new GenericTextRunProperties(_currentRendering));

    結(jié)束段落

    告訴段落結(jié)束的辦法是在GetTextRun方法中返回TextEndOfParagraph,比如默認當索引字符等于輸出字符長度時則認為段落結(jié)束
    if (textSourceCharacterIndex > _text.Length) {return new TextEndOfParagraph(1); }

    在段落添加額外的文字,在輸出文字結(jié)束以后添加段落末尾的文字,如下圖EndTextWord可以以自行的邏輯添加

    var customEndText = "EndTextWord"; var gap = textSourceCharacterIndex - _text.Length; if (gap >= 0 && gap < customEndText.Length) {_currentRendering.FontSize = 24;return new TextCharacters(customEndText,0,customEndText.Length,new GenericTextRunProperties(_currentRendering)); } if (gap >= customEndText.Length) {return new TextEndOfParagraph(1); }

    多段落

    如下文字

    若窗體寬度不夠的話,將換行顯示

    在TextLine調(diào)用Draw方法以后,若寬度不夠,將只呈現(xiàn)部分文字,并有一個Length屬性,然后可以根據(jù)Length屬性繼續(xù)呈現(xiàn)第二段文字.如下代碼(僅做示例而用)

    TextLine myTextLine = formatter.FormatLine(textStore,0,80,new GenericTextParagraphProperties(currentRendering),null); myTextLine.Draw(dc, new Point(0, 0), InvertAxes.None); myTextLine.Dispose(); // Draw second paragraph. using (TextLine myTextLine2 = formatter.FormatLine(textStore,myTextLine.Length,80,new GenericTextParagraphProperties(currentRendering),null)) {myTextLine2.Draw(dc, new Point(0, 25), InvertAxes.None); }

    現(xiàn)在

    轉(zhuǎn)載于:https://www.cnblogs.com/Clingingboy/archive/2010/12/03/1895460.html

    總結(jié)

    以上是生活随笔為你收集整理的WPF 文本呈现(2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。