Ich möchte ein Textfeld mit der folgenden Logik haben:
< /p>
Der Effekt kann nicht präzise sein. bis Sie 400. < /p>
erreichenwhile (true)
{
double w = MeasureTextBlock(tbx).Width;
if (w > 400)
{
tbx.Text += w;
break;
}
else
tbx.Text += ".";
}
< /code>
und der Kern von allem ist die Funktion: < /p>
private Size MeasureTextBlock(TextBlock tb)
{
var formattedText = new FormattedText(
tb.Text,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(tb.FontFamily, tb.FontStyle, tb.FontWeight, tb.FontStretch),
tb.FontSize,
Brushes.Black,
new NumberSubstitution(),
VisualTreeHelper.GetDpi(tb).PixelsPerDip);
return new Size(formattedText.Width, formattedText.Height);
}
< /code>
Es scheint mir, dass diese Funktion nicht richtig funktioniert (siehe oben Zeile1 ist 401 länger als Zeile 3 403 ??), aber ich kann nicht verstehen, was darin los ist.>
Wie man eine summarische Textbox hat ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post