using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int xt = -1;
int lx = pictureBox1.Width / 4, ly = pictureBox1.Height / 4;
int num = 3;
//while(true)
{
xt++;
num++;
e.Graphics.DrawLine(Pens.Black, 0, pictureBox1.Height / 2, pictureBox1.Width, pictureBox1.Height / 2);//X轴//
e.Graphics.DrawLine(Pens.Black, pictureBox1.Width / 2, 0, pictureBox1.Width / 2, pictureBox1.Height);//Y轴//
//画出坐标轴,十字型,原点位于图像中心//
for (int i = 1; i <= num; i++)
{
e.Graphics.DrawLine(Pens.Black, lx * (num - 1) / num * i, pictureBox1.Height / 2, lx * (num - 1) / num * i, pictureBox1.Height / 2 - 5);
//画图X轴刻度线,分度为1,长度为10,刻度线的高度为2,//
e.Graphics.DrawString((i - 2).ToString(), new Font("宋体", 10), new SolidBrush(Color.Green), lx * (num - 1) / num * i - 5, pictureBox1.Height / 2);
// 写出刻度数字,i-5表示零点位置在坐标中心//
}
// (i - 2).ToString() 将此实例的数值转换为其等效的字符串表示形式
// new Font("宋体", 10)设置字体和大小
// new SolidBrush(Color.Green) 设置字体颜色为绿色
for (int j = 1; j < 4; j++) //画出Y轴刻度
{
e.Graphics.DrawLine(Pens.Black, pictureBox1.Width / 2, ly * j, pictureBox1.Width / 2 + 5, ly * j);
if (j - 2 != 0)
e.Graphics.DrawString((j - 2).ToString(), new Font("宋体", 10), new SolidBrush(Color.Green), pictureBox1.Width / 2 - 15, pictureBox1.Height / 4 * j);
}
int size = 350;
double[] x = new double[size];
Pen pen = new Pen(Color.Blue);
int val = 2;
float temp = 0.0f;
//e.Graphics.TranslateTransform(pictureBox1.Width / 5, pictureBox1.Height / 2);//X,Y平移,平移坐标轴
for (int i = 0; i < size; i++)
{
x[i] = Math.Sin(2 * Math.PI * i / pictureBox1.Width * 10 / 3) * pictureBox1.Height / 4;
e.Graphics.DrawLine(pen, i * val * (num - 1) / num, temp + Convert.ToSingle(2 * ly), (i * val + val / 2) * (num - 1) / num, (float)x[i] + Convert.ToSingle(2 * ly));
temp = (float)x[i];
}
Thread.Sleep(10);
//pictureBox1.Image.Dispose();
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
int xt = -1;
int lx = pictureBox1.Width / 4, ly = pictureBox1.Height / 4;
int num = 3;
//while(true)
{
xt++;
num++;
e.Graphics.DrawLine(Pens.Black, 0, pictureBox1.Height / 2, pictureBox1.Width, pictureBox1.Height / 2);//X轴//
e.Graphics.DrawLine(Pens.Black, pictureBox1.Width / 2, 0, pictureBox1.Width / 2, pictureBox1.Height);//Y轴//
//画出坐标轴,十字型,原点位于图像中心//
for (int i = 1; i <= num; i++)
{
e.Graphics.DrawLine(Pens.Black, lx * (num - 1) / num * i, pictureBox1.Height / 2, lx * (num - 1) / num * i, pictureBox1.Height / 2 - 5);
//画图X轴刻度线,分度为1,长度为10,刻度线的高度为2,//
e.Graphics.DrawString((i - 2).ToString(), new Font("宋体", 10), new SolidBrush(Color.Green), lx * (num - 1) / num * i - 5, pictureBox1.Height / 2);
// 写出刻度数字,i-5表示零点位置在坐标中心//
}
// (i - 2).ToString() 将此实例的数值转换为其等效的字符串表示形式
// new Font("宋体", 10)设置字体和大小
// new SolidBrush(Color.Green) 设置字体颜色为绿色
for (int j = 1; j < 4; j++) //画出Y轴刻度
{
e.Graphics.DrawLine(Pens.Black, pictureBox1.Width / 2, ly * j, pictureBox1.Width / 2 + 5, ly * j);
if (j - 2 != 0)
e.Graphics.DrawString((j - 2).ToString(), new Font("宋体", 10), new SolidBrush(Color.Green), pictureBox1.Width / 2 - 15, pictureBox1.Height / 4 * j);
}
int size = 350;
double[] x = new double[size];
Pen pen = new Pen(Color.Blue);
int val = 2;
float temp = 0.0f;
//e.Graphics.TranslateTransform(pictureBox1.Width / 5, pictureBox1.Height / 2);//X,Y平移,平移坐标轴
for (int i = 0; i < size; i++)
{
x[i] = Math.Sin(2 * Math.PI * i / pictureBox1.Width * 10 / 3) * pictureBox1.Height / 4;
e.Graphics.DrawLine(pen, i * val * (num - 1) / num, temp + Convert.ToSingle(2 * ly), (i * val + val / 2) * (num - 1) / num, (float)x[i] + Convert.ToSingle(2 * ly));
temp = (float)x[i];
}
Thread.Sleep(10);
//pictureBox1.Image.Dispose();
}
}
}
}

楠小南

