2012-04-21 3 views
0

MonoMac에 텍스트를 그리려하고 있지만 성공하지 못했습니다. 제공된 샘플에서 원이 그려지지만 텍스트가 나타나지 않습니다.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 

감사

답변

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"); 
} 
0

당신은 단지 drawRect를 다시 작성해야합니다.

public override void DrawRect (RectangleF dirtyRect) 
    { 
     NSString s = new NSString ("test"); 
     s.DrawString (new PointF(25,100), new NSDictionary()); 
    } 

사용자 정의하려는 경우 여기에 good reference입니다.