本文介绍了如何使用自定义坐标绘制线条或点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hi all,
I am new at GDI and graphics and will like some help trying to draw lines or plot points.
I have the following code and do not understand why the line is not drawn?
using System;
using System.Drawing;
using System.Windows.Forms;
namespace lineplot
{
public partial class Form1 : Form
{
private Rectangle drawingRectangle;
private float xMin = 500000f;
private float xMax = 600000f;
private float yMin = 5000000f;
private float yMax = 6000000f;
private int offset = 10;
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.BackColor = Color.White;
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
Rectangle rect = ClientRectangle;
drawingRectangle = new Rectangle(rect.Location, rect.Size);
drawingRectangle.Inflate(-offset, -offset);
g.DrawRectangle(Pens.Red, rect);
g.DrawRectangle(Pens.Black, drawingRectangle);
Pen aPen = new Pen(Color.Green, 3);
g.DrawLine(aPen, Point2D(new PointF(695312, 5668062)),
Point2D(new PointF(695312, 5668100)));
aPen.Dispose();
g.Dispose();
}
private PointF Point2D(PointF ptf)
{
PointF aPoint = new PointF();
aPoint.X = drawingRectangle.X + (ptf.X - xMin) *
drawingRectangle.Width / (xMax - xMin);
aPoint.Y = drawingRectangle.Bottom - (ptf.Y - yMin) *
drawingRectangle.Height / (yMax - yMin);
return aPoint;
}
}
}<pre lang="c#">
推荐答案
这篇关于如何使用自定义坐标绘制线条或点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!