C# MonoMac中的绘图文本
我试图用MonoMac绘制一些文本,但没有成功。 在提供的示例中,绘制了圆,但未显示文本C# MonoMac中的绘图文本,c#,monomac,C#,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
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
谢谢您只需指定要使用的字体即可
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");
}
你只需要重写drawRect
public override void DrawRect (RectangleF dirtyRect)
{
NSString s = new NSString ("test");
s.DrawString (new PointF(25,100), new NSDictionary ());
}
如果你想定制它,这里有一个