在c#中绘制一个x^2+sinx的图像的程序是什么
答案:1 悬赏:10 手机版
解决时间 2021-12-01 22:57
- 提问者网友:情歌越听越心酸
- 2021-12-01 07:00
在c#中绘制一个x^2+sinx的图像的程序是什么
最佳答案
- 五星知识达人网友:千杯敬自由
- 2021-12-01 07:31
新建Form,粘贴如下代码
public partial class Form1 : Form
{
PictureBox p;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
p = new PictureBox();
p.Dock = DockStyle.Fill;
this.Controls.Add(p);
p.Paint += this.p_Paint;
}
private void p_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
for (float x = -30; x <= 30; x += 0.01f)
{
PointF p = new PointF(
(float)x, x * x + (float)Math.Sin(x));
this.DrawPoint(g, ref p);
}
}
private void DrawPoint(Graphics g, ref PointF p)
{
p.X = p.X + this.p.Width / 2;
p.Y = this.p.Height / 2 - p.Y;
g.DrawEllipse(new Pen(Color.Red),
new RectangleF(p, new SizeF(1, 1)));
}
}
public partial class Form1 : Form
{
PictureBox p;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
p = new PictureBox();
p.Dock = DockStyle.Fill;
this.Controls.Add(p);
p.Paint += this.p_Paint;
}
private void p_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
for (float x = -30; x <= 30; x += 0.01f)
{
PointF p = new PointF(
(float)x, x * x + (float)Math.Sin(x));
this.DrawPoint(g, ref p);
}
}
private void DrawPoint(Graphics g, ref PointF p)
{
p.X = p.X + this.p.Width / 2;
p.Y = this.p.Height / 2 - p.Y;
g.DrawEllipse(new Pen(Color.Red),
new RectangleF(p, new SizeF(1, 1)));
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯