Megjegyzés
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhat bejelentkezni vagy módosítani a címtárat.
Az oldalhoz való hozzáféréshez engedély szükséges. Megpróbálhatja módosítani a címtárat.
A következő példa megmutatja, hogyan rajzolhat szöveget egy DrawingVisual-ra egy DrawingContext objektum segítségével. A rendszer egy RenderOpen objektum DrawingVisual metódusának meghívásával ad vissza egy rajzkörnyezetet. Rajzkörnyezetbe rajzolhat grafikát és szöveget.
Ha szöveget szeretne rajzolni a rajzkörnyezetbe, használja egy DrawText objektum DrawingContext metódusát. Ha befejezte a tartalom rajzolását a rajzkörnyezetbe, hívja meg a Close metódust a rajzkörnyezet bezárásához és a tartalom megőrzéséhez.
példa
// Create a DrawingVisual that contains text.
private DrawingVisual CreateDrawingVisualText()
{
// Create an instance of a DrawingVisual.
DrawingVisual drawingVisual = new DrawingVisual();
// Retrieve the DrawingContext from the DrawingVisual.
DrawingContext drawingContext = drawingVisual.RenderOpen();
// Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(
new FormattedText("Click Me!",
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
36, System.Windows.Media.Brushes.Black),
new System.Windows.Point(200, 116));
// Close the DrawingContext to persist changes to the DrawingVisual.
drawingContext.Close();
return drawingVisual;
}
' Create a DrawingVisual that contains text.
Private Function CreateDrawingVisualText() As DrawingVisual
' Create an instance of a DrawingVisual.
Dim drawingVisual As New DrawingVisual()
' Retrieve the DrawingContext from the DrawingVisual.
Dim drawingContext As DrawingContext = drawingVisual.RenderOpen()
' Draw a formatted text string into the DrawingContext.
drawingContext.DrawText(New FormattedText("Click Me!", CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, New Typeface("Verdana"), 36, Brushes.Black), New Point(200, 116))
' Close the DrawingContext to persist changes to the DrawingVisual.
drawingContext.Close()
Return drawingVisual
End Function
Megjegyzés:
A teljes kódmintát, ahonnan az előző kódpéldát származtatták, lásd: Hit Test Using DrawingVisuals Sample.
.NET Desktop feedback