0

MonoMac でテキストを描画しようとしていますが、うまくいきません。提供されたサンプルでは、​​円が描画されますが、テキストは表示されません。

var context = NSGraphicsContext.CurrentContext.GraphicsPort;
context.SetStrokeColor (new CGColor(1.0f, 0f, 0f)); // red
context.SetLineWidth (1.0F);
context.StrokeEllipseInRect (new RectangleF(5, 5, 10, 10));
context.SetTextDrawingMode(CGTextDrawingMode.Stroke);
context.TextPosition = new PointF(0f, 0f);
context.ShowText("My text"); // is not shown

ありがとう

4

2 に答える 2

0

使用したいフォントを指定するだけです。

public override void DrawRect (RectangleF dirtyRect)
{
    var context = NSGraphicsContext.CurrentContext.GraphicsPort;

    context.SetStrokeColor (new CGColor(1.0f, 0f, 0f)); // red
    context.SetLineWidth (1.0F);
    context.StrokeEllipseInRect (new RectangleF(5, 5, 10, 10));
    context.SetTextDrawingMode(CGTextDrawingMode.Stroke);
    context.TextPosition = new PointF(0f, 0f);
    context.SelectFont ("Arial", 5, CGTextEncoding.MacRoman);
    context.ShowText("My text");
}
于 2012-08-10T00:28:09.950 に答える