菜鸟提问-如何Form的时候就显示一个带网格的坐标系
初学C# 很多语法还不是很明白。
现在要用C#写一个程序,用于实时显示数据波形。
但是第一步就是要初始化一个带网格的坐标系。用picturebox来做的。可是运行并没出现网格。
还请大神们不吝赐教!小女子十分感谢!!!
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
#region **私有函数 波形显示区域Paint **
private void pictureBoxGraph_Paint(object sender, PaintEventArgs e)
{
#region **绘图参数初始化**
int width = pictureBoxGraph.Width;
int height = pictureBoxGraph.Height;
Graphics Grap = e.Graphics;
int i = 0;
float eachx = 0;
float eachy = 0;
float drawx = 0;
float drawy = 0;
#endregion
Pen myPen = new Pen(Color.Red, 1f);
#region **画垂直网格**
eachx = width / 200;
eachy = height / 100;
for (i = 0; i < 200; i++)
{
drawx += eachx;
Grap.DrawLine(myPen, drawx, 0, drawx, height);
}
for (i = 0; i < 100; i++)
{
drawy += eachy;
Grap.DrawLine(myPen, 0, drawy, width, drawy);