C# 把线画到椭圆的中心

C# 把线画到椭圆的中心,c#,drawing,C#,Drawing,我有简单的代码,可以画一个椭圆。我想在这个椭圆的中心画一个数字,怎么做 绘制椭圆的代码为: Point point = p.PointToClient(Cursor.Position); float radius = 13.0f; float x = point.X - radius; float y = point.Y - radius; float width = 2 * radius; float height = 2 * radius; graphicsObj.FillEllipse(m

我有简单的代码,可以画一个椭圆。我想在这个椭圆的中心画一个数字,怎么做

绘制椭圆的代码为:

Point point = p.PointToClient(Cursor.Position);
float radius = 13.0f;
float x = point.X - radius;
float y = point.Y - radius;
float width = 2 * radius;
float height = 2 * radius;
graphicsObj.FillEllipse(myBrush, x, y, width, height);
用于在周围矩形的中心绘制文本。指定“对齐”和“线性对齐”设置为StringAlignment的对象。居中:

RectangleF bounds = new RectangleF(x, y, width, height);
using (StringFormat format = new StringFormat()) {
    format.Alignment = StringAlignment.Center;
    format.LineAlignment = StringAlignment.Center;
    graphicsObj.DrawText("Number", SystemFonts.Default, Brushes.Black, bounds, format);
}
用于在周围矩形的中心绘制文本。指定“对齐”和“线性对齐”设置为StringAlignment的对象。居中:

RectangleF bounds = new RectangleF(x, y, width, height);
using (StringFormat format = new StringFormat()) {
    format.Alignment = StringAlignment.Center;
    format.LineAlignment = StringAlignment.Center;
    graphicsObj.DrawText("Number", SystemFonts.Default, Brushes.Black, bounds, format);
}

您可以使用以下方法进行操作:

public void FillEllipse(
    Brush brush,
    Rectangle rect
)

即:

graphicsObj.FillEllipse(brush,rect);
graphicsObj.DrawString("Number Here", new Font("Arial", 13f), Brushes.Black, sameRectangleOfEllipse);

您可以使用以下方法进行操作:

public void FillEllipse(
    Brush brush,
    Rectangle rect
)

即:

graphicsObj.FillEllipse(brush,rect);
graphicsObj.DrawString("Number Here", new Font("Arial", 13f), Brushes.Black, sameRectangleOfEllipse);