c#创建画布_c#新建一个画图的类,里面画坐标轴方法的Graphics g 怎么赋初值

c#新建一个画图的类,里面画坐标轴方法的Graphics g 如何赋初值?

我新建一个winform,添加一个panel1

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

string[] stationname = { "宋家庄站", "刘家窑站" };

double[] stationposition = { 0.424, 2.095 };

private void panel1_Paint(object sender, PaintEventArgs e)

{

Draw draw1 = new Draw();

draw1.DrawAxis(stationposition, stationname);

}

}

然后新建一个class Draw的类

class Draw

{

//画布

//背景

//坐标原点

int x=100;

int y=540;

//位置放大比例

double stationposition_ratio = 500;

//字体

Font fontO = new System.Drawing.Font("Arial", 9, FontStyle.Regular);

Font fontT = new System.Drawing.Font("宋体", 12, FontStyle.Regular);

//画笔

Pen traction_pen = new Pen(Color.Red, 2);

Pen coasting_pen = new Pen(Color.Green, 2);

Pen brake_pen = new Pen(Color.Blue, 2);

Pen axis_pen = new Pen(Color.White);

//画刷

Brush brush = new SolidBrush(Color.White);

//画坐标线

public  void DrawAxis(double[] stationposition,string[] stationname)

{

Graphics g = CreateGraphics();

//背景色

g.Clear(Color.Black);

//车站中心线

for (int i = 0; i 

{

g.DrawLine(axis_pen, x + (int)(stationposition[i] * stationposition_ratio), y, x + (int)(stationposition[i] * stationposition_ratio), y - 500);

g.DrawLine(axis_pen, x + (int)(stationposition[i] * stationposition_ratio - 50), y - 500, (int)(x + stationposition[i] * stationposition_ratio + 50), y - 500);

g.DrawString(stationname[i] + " " + stationposition[i].ToString() + "km", fontT, brush, (int)(x + stationposition[i] * stationposition_ratio - 70), y - 520);

}

//y轴-速度

g.DrawLine(axis_pen, x, y, x, y - 500);

int k = y;

string[] v_value = { "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100" };

for (int i = 0; i 

{

g.DrawString(v_value[i].ToString(), fontO, brush, x - 30, k);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值