资源简介
用C#绘制正弦曲线,要用到Form1_Resize,Form1_Paint两个方法,C#源代码
int x1, x2;
double y1, y2;
double a;
Pen myPen = new Pen(Color.Blue, 3);
x1 = x2 = 0;
y1 = y2 = this.ClientSize.Height / 2;
for (x2 = 0; x2 < this.ClientSize.Width; x2++)
{
a = 2 * Math.PI * x2 / this.ClientSize.Width;
y2 = Math.Sin(a);
y2 = (1 - y2) * this.ClientSize.Height / 2;
e.Graphics.DrawLine(myPen, x1, (float)y1, x2, (float
)y2);
x1 = x2;
y1 = y2;
}
int x1, x2;
double y1, y2;
double a;
Pen myPen = new Pen(Color.Blue, 3);
x1 = x2 = 0;
y1 = y2 = this.ClientSize.Height / 2;
for (x2 = 0; x2 < this.ClientSize.Width; x2++)
{
a = 2 * Math.PI * x2 / this.ClientSize.Width;
y2 = Math.Sin(a);
y2 = (1 - y2) * this.ClientSize.Height / 2;
e.Graphics.DrawLine(myPen, x1, (float)y1, x2, (float
)y2);
x1 = x2;
y1 = y2;
}
代码片段和文件信息
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;
namespace Sin
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Paint(object sender PaintEventArgs e)
{
int x1 x2;
double y1 y2;
double a;
Pen myPen = new Pen(Color.Blue 3);
x1 = x2 = 0;
y1 = y2 = this.ClientSize.Height / 2;
for (x2 = 0; x2 < this.ClientSize.Width; x2++)
{
a = 2 * Math.PI * x2 / this.ClientSize.Width;
y2 = Math.Sin(a);
y2 = (1 - y2) * this.ClientSize.Height / 2;
e.Graphics.DrawLine(myPen x1 (float)y1 x2 (float)y2);
x1 = x2;
y1 = y2;
}
}
private void Form1_Resize(object sender EventArgs e)
{
this.Invalidate();
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
I.A.... 8192 2008-12-31 10:54 Sin\Sin\bin\Debug\Sin.exe
I.A.... 22016 2008-12-31 10:54 Sin\Sin\bin\Debug\Sin.pdb
I.A.... 14328 2008-12-31 10:54 Sin\Sin\bin\Debug\Sin.vshost.exe
I.A.... 490 2007-07-21 02:33 Sin\Sin\bin\Debug\Sin.vshost.exe.manifest
I.A.... 1147 2008-12-31 10:56 Sin\Sin\Form1.cs
I.A.... 1551 2008-12-31 10:54 Sin\Sin\Form1.Designer.cs
I.A.... 5814 2008-12-31 10:54 Sin\Sin\Form1.resx
I.A.... 328 2008-12-31 10:54 Sin\Sin\obj\Debug\Sin.csproj.FileListAbsolute.txt
I.A.... 847 2008-12-31 10:54 Sin\Sin\obj\Debug\Sin.csproj.GenerateResource.Cache
I.A.... 8192 2008-12-31 10:54 Sin\Sin\obj\Debug\Sin.exe
I.A.... 180 2008-12-31 10:54 Sin\Sin\obj\Debug\Sin.Form1.resources
I.A.... 22016 2008-12-31 10:54 Sin\Sin\obj\Debug\Sin.pdb
I.A.... 180 2008-12-31 10:51 Sin\Sin\obj\Debug\Sin.Properties.Resources.resources
I.A.... 484 2008-12-31 10:51 Sin\Sin\Program.cs
I.A.... 1362 2008-12-31 10:51 Sin\Sin\Properties\AssemblyInfo.cs
I.A.... 2856 2008-12-31 10:51 Sin\Sin\Properties\Resources.Designer.cs
I.A.... 5612 2008-12-31 10:51 Sin\Sin\Properties\Resources.resx
I.A.... 1088 2008-12-31 10:51 Sin\Sin\Properties\Settings.Designer.cs
I.A.... 249 2008-12-31 10:51 Sin\Sin\Properties\Settings.settings
I.A.... 3717 2008-12-31 10:51 Sin\Sin\Sin.csproj
I.A.... 899 2008-12-31 10:51 Sin\Sin.sln
I.A..H. 12288 2008-12-31 10:57 Sin\Sin.suo
I.A.... 734 2008-12-31 10:57 Sin\新建 文本文档.txt
I..D... 0 2008-12-31 10:51 Sin\Sin\obj\Debug\TempPE
I..D... 0 2008-12-31 10:53 Sin\Sin\bin\Debug
I..D... 0 2008-12-31 10:54 Sin\Sin\obj\Debug
I..D... 0 2008-12-31 10:51 Sin\Sin\bin
I..D... 0 2008-12-31 10:51 Sin\Sin\obj
I..D... 0 2008-12-31 10:51 Sin\Sin\Properties
I..D... 0 2008-12-31 10:56 Sin\Sin
............此处省略4个文件信息
- 上一篇:c# 鼠标绘图 并保存到本地
- 下一篇:C# WinForm读写INI文件
评论
共有 条评论