菜鸟提问-如何Form的时候就显示一个带网格的坐标系

maomao131418 2014-03-10 07:43:56

初学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);


}

#endregion




}
#endregion




public Form1()
{
InitializeComponent();

}




}
}
...全文
151 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
大湿级 2014-03-11
  • 打赏
  • 举报
回复
楼主变性了,为啥是小女子。
百事洞明 2014-03-10
  • 打赏
  • 举报
回复
网格线条件,水平坐标相同,竖直坐标++ 或者相反,你监听X Y 值来查错
BenBenBears 2014-03-10
  • 打赏
  • 举报
回复

        public Form1()
        {
            InitializeComponent();
                        this.pictureBoxGraph.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBoxGraph_Paint);//添加事件绑定
        }
maomao131418 2014-03-10
  • 打赏
  • 举报
回复
楼上 请问为什么我执行是光秃秃的图啊 什么都没有????
BenBenBears 2014-03-10
  • 打赏
  • 举报
回复
BenBenBears 2014-03-10
  • 打赏
  • 举报
回复
以下姑娘代码执行的结果,请笑纳!

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧