は、私は、次のサンプルコードを示しているthis article on MSDN accrossに来た:CustomTextParagraphPropertiesにアクセスするには何を参照する必要がありますか? TextFormatterでの作業
// Create a TextFormatter object.
TextFormatter formatter = TextFormatter.Create();
// Create common paragraph property settings.
CustomTextParagraphProperties customTextParagraphProperties
= new CustomTextParagraphProperties();
// Format each line of text from the text store and draw it.
while (textStorePosition < customTextSource.Text.Length)
{
// Create a textline from the text store using the TextFormatter object.
using (TextLine myTextLine = formatter.FormatLine(
customTextSource,
textStorePosition,
96 * 6,
customTextParagraphProperties,
null))
{
// Draw the formatted text into the drawing context.
myTextLine.Draw(drawingContext, linePosition, InvertAxes.None);
// Update the index position in the text store.
textStorePosition += myTextLine.Length;
// Update the line position coordinate for the displayed line.
linePosition.Y += myTextLine.Height;
}
}
私が午前問題もCustomTextParagraphProperties
を使用して何のクラス/オブジェクトがないSystem.Windows.Media.TextFormatting
を参照した後になるように行がエラー(のがスローされますコースが存在しないため)
このクラスにアクセスするには、他に何が必要ですか?
これは私のusing
リストです:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Drawing.Printing;
using System.ComponentModel;
using System.Windows.Media.TextFormatting;
using System.IO;
そして、これは私の参照のリストです:
私はTextParagraphProperties
が見つかりましたが、これはabstract
クラスであり、このようにして作成することができませんnew
を使用しています。つまり、例のようにCustomTextParagraphProperties
の代わりに値下がりすることはないので、次の行は機能しません。
TextParagraphProperties tp = new TextParagraphProperties();
注:このプロジェクトはWPF機能を継承するため、WPFタグを追加しましたが、これはWPFプロジェクトではありません。
私はウサギの穴を下に掘り下げるために始めた、と親がに依存し、より多くのcodependantabstract
クラスの検索、およびオブジェクトをinistializeする
new
を使用できないため、無最後にして、コードの束を記述する必要があります光景、これはかなりイライラさせられる:
#region textformatter
class TextRunProperties : System.Windows.Media.TextFormatting.TextRunProperties {
public override Windows.Media.Brush BackgroundBrush { get; set; }
public override Windows.BaselineAlignment BaselineAlignment { get { return base.BaselineAlignment; } }
public override CultureInfo CultureInfo { get; set; }
public override double FontHintingEmSize { get; set; }
public override double FontRenderingEmSize { get; set; }
public override Windows.Media.Brush ForegroundBrush { get; set; }
public override Windows.Media.NumberSubstitution NumberSubstitution { get { return base.NumberSubstitution; } }
public override TextDecorationCollection TextDecorations { get; set; }
public override Windows.Media.TextEffectCollection TextEffects { get; set; }
public override Windows.Media.Typeface Typeface { get; set; }
public override Windows.Media.TextFormatting.TextRunTypographyProperties TypographyProperties { get { return base.TypographyProperties; } }
}
class TextRun : System.Windows.Media.TextFormatting.TextRun {
public override CharacterBufferReference CharacterBufferReference { get; set; }
public override int Length { get; set; }
public override Windows.Media.TextFormatting.TextRunProperties Properties { get; set; }
}
class TextSource : System.Windows.Media.TextFormatting.TextSource {
public override Windows.Media.TextFormatting.TextSpan<CultureSpecificCharacterBufferRange> GetPrecedingText(int textSourceCharacterIndexLimit) {
return new TextSpan<CultureSpecificCharacterBufferRange>(
textSourceCharacterIndexLimit,
new CultureSpecificCharacterBufferRange(
new CultureInfo(0),
Windows.Media.TextFormatting.CharacterBufferRange.Empty
)
);
}
public override int GetTextEffectCharacterIndexFromTextSourceCharacterIndex(int textSourceCharacterIndex) {
return 0;
}
public override Windows.Media.TextFormatting.TextRun GetTextRun(int textSourceCharacterIndex) {
return new TextRun();
}
}
class TextFormatter : System.Windows.Media.TextFormatting.TextFormatter {
public override Windows.Media.TextFormatting.TextLine FormatLine(Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak, TextRunCache textRunCache) {
throw new NotImplementedException();
}
public override Windows.Media.TextFormatting.TextLine FormatLine(Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, double paragraphWidth, TextParagraphProperties paragraphProperties, TextLineBreak previousLineBreak) {
throw new NotImplementedException();
}
public override Windows.Media.TextFormatting.MinMaxParagraphWidth FormatMinMaxParagraphWidth(Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, TextParagraphProperties paragraphProperties) {
throw new NotImplementedException();
}
public override Windows.Media.TextFormatting.MinMaxParagraphWidth FormatMinMaxParagraphWidth(Windows.Media.TextFormatting.TextSource textSource, int firstCharIndex, TextParagraphProperties paragraphProperties, TextRunCache textRunCache) {
throw new NotImplementedException();
}
}
class TextLine : System.Windows.Media.TextFormatting.TextLine {
public override double Baseline {
get { throw new NotImplementedException(); }
}
public override int DependentLength {
get { throw new NotImplementedException(); }
}
public override double Extent {
get { throw new NotImplementedException(); }
}
public override bool HasCollapsed {
get { throw new NotImplementedException(); }
}
public override bool HasOverflowed {
get { throw new NotImplementedException(); }
}
public override double Height {
get { throw new NotImplementedException(); }
}
public override bool IsTruncated {
get {
return base.IsTruncated;
}
}
public override int Length {
get { throw new NotImplementedException(); }
}
public override double MarkerBaseline {
get { throw new NotImplementedException(); }
}
public override double MarkerHeight {
get { throw new NotImplementedException(); }
}
public override int NewlineLength {
get { throw new NotImplementedException(); }
}
public override double OverhangAfter {
get { throw new NotImplementedException(); }
}
public override double OverhangLeading {
get { throw new NotImplementedException(); }
}
public override double OverhangTrailing {
get { throw new NotImplementedException(); }
}
public override double Start {
get { throw new NotImplementedException(); }
}
public override double TextBaseline {
get { throw new NotImplementedException(); }
}
public override double TextHeight {
get { throw new NotImplementedException(); }
}
public override int TrailingWhitespaceLength {
get { throw new NotImplementedException(); }
}
public override double Width {
get { throw new NotImplementedException(); }
}
public override double WidthIncludingTrailingWhitespace {
get { throw new NotImplementedException(); }
}
// functions
public override Windows.Media.TextFormatting.TextLine Collapse(params TextCollapsingProperties[] collapsingPropertiesList) {
throw new NotImplementedException();
}
public override void Draw(DrawingContext drawingContext, Windows.Point origin, InvertAxes inversion) {
throw new NotImplementedException();
}
public override CharacterHit GetBackspaceCaretCharacterHit(CharacterHit characterHit) {
throw new NotImplementedException();
}
public override CharacterHit GetCharacterHitFromDistance(double distance) {
throw new NotImplementedException();
}
public override double GetDistanceFromCharacterHit(CharacterHit characterHit) {
throw new NotImplementedException();
}
public override IEnumerable<IndexedGlyphRun> GetIndexedGlyphRuns() {
throw new NotImplementedException();
}
public override CharacterHit GetNextCaretCharacterHit(CharacterHit characterHit) {
throw new NotImplementedException();
}
public override CharacterHit GetPreviousCaretCharacterHit(CharacterHit characterHit) {
throw new NotImplementedException();
}
public override IList<TextBounds> GetTextBounds(int firstTextSourceCharacterIndex, int textLength) {
throw new NotImplementedException();
}
public override IList<TextCollapsedRange> GetTextCollapsedRanges() {
throw new NotImplementedException();
}
public override TextLineBreak GetTextLineBreak() {
throw new NotImplementedException();
}
public override IList<TextSpan<Windows.Media.TextFormatting.TextRun>> GetTextRunSpans() {
throw new NotImplementedException();
}
}
#endregion
私もそれが正しいかどうかを知り、それが思われるものから、これらのmust override
方法のいずれも、何も返さないので、このクラスでは、正確に何をするのかないのですか? TextEffectを取得するなどのコードを処理するかどうか、または手作業で書かなければならないすべてのものですか?自分自身のTextEffectを作成して、そのコードに抽象構造を追加する必要があります。何もしない....
私はちょうどそれを見ていて、終わりのないウサギの穴のようです。私の質問を更新して、私が始めた実装を含めますが、分かりません。 'TextRunProperties'と他の様々な抽象クラスが何もしていないということを理解するのは間違いありません。そのような構造を必要とするのはむしろ愚かなようですが、クラスの新しいインスタンスが一つのプロパティ(例えばtext )そして、代わりにいくつかのデフォルトを用意しています...まあ...実際にMSの部分のLAZY XD –
基本的には、コンストラクタ/クラスに文字列を渡してから、それを処理します。 'richTextBox1.Text =" foo "'のように、コントロールは自動的にその文字列をRTF形式に変換します。私はクラスを抽象化してRTF仕様全体を手作業で書くだけで、RichTextBoxにテキストを設定する必要はありません。 –