gpt4 book ai didi

c# 你可以在没有表单的情况下从轴获取位置吗?

转载 作者:太空宇宙 更新时间:2023-11-03 16:45:38 25 4
gpt4 key购买 nike

我有一个 WinForm 应用程序,我想将其转换为服务。它上面有两个mscharts。我不再需要查看这些图表,因为应用程序会根据它们创建位图。我根据另一张图表中的数据在一张图表上画一条线,如下所示:

// Get Graphics object from chart
Graphics graph = e.ChartGraphics.Graphics;

// Convert X and Y values to screen position
float pixelYMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, CreatininePoint.YValues[0]);
float pixelXMax = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, CreatininePoint.XValue);
float pixelYMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, CreatininePoint.YValues[0]-20);
float pixelXMin = (float)e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, CreatininePoint.XValue);

PointF point1 = PointF.Empty;
PointF point2 = PointF.Empty;

// Set Maximum and minimum points
point1.X = pixelXMax;
point1.Y = pixelYMax-10;
point2.X = pixelXMin;
point2.Y = 84;

// Convert relative coordinates to absolute coordinates.
point1 = e.ChartGraphics.GetAbsolutePoint(point1);
point2 = e.ChartGraphics.GetAbsolutePoint(point2);

float[] dashValues = { 4,2 };
Pen blackPen = new Pen(Color.Black, 1);
blackPen.DashPattern = dashValues;
//e.Graphics.DrawLine(blackPen, new Point(5, 5), new Point(405, 5));
//graph.DrawLine(blackPen, point1, point2);

// Draw connection line
graph.DrawLine(new Pen(Color.Black, 2), point2, point1);

// Create string to draw.
//String drawString = creatininept + " ng/mL";
String drawString = "67 ng/mL";

// Create font and brush.
Font drawFont = new Font("Arial", 7);
SolidBrush drawBrush = new SolidBrush(Color.Black);

// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(point1.X,point1.Y+5);

// Draw string to screen.
graph.DrawString(drawString, drawFont, drawBrush, drawPoint);

是否可以在没有表单的情况下执行此操作以便我们可以运行服务?

最佳答案

Bitmap canvas = new Bitmap(600, 480);
Graphics graph = Graphics.FromImage(canvas);

..然后继续绘制图表。

关于c# 你可以在没有表单的情况下从轴获取位置吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6129788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com