111,129
社区成员
发帖
与我相关
我的任务
分享
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.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
bool b = false;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
b = true;
pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
SolidBrush sb = new SolidBrush(Color.Black);//话刷
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 1);
Point[] xpts = new Point[3] {
new Point(410 - 35, 108),
new Point(410 - 35, 112),
new Point(410 - 30, 110)
};
g.DrawLine(p, 30, 110, 410 - 30, 110);
g.DrawPolygon(p, xpts);
g.DrawString("X", new Font("宋体", 9), sb, 410 - 25, 105);
Point[] ypts = new Point[3] {
new Point(28, 25),
new Point(30, 20),
new Point(32, 25) };
g.DrawLine(p, 30, 232 - 30, 30, 20);
g.DrawPolygon(p, ypts);
g.DrawString("Y", new Font("宋体", 9), sb, 15, 20);
Graphics g1 = CreateGraphics();
int o = int.Parse(comboBox2.Text);
int n = int.Parse(comboBox3.Text);
int m = int.Parse(comboBox1.Text);
if (b != true) return;
for (int l = 0; l <= 230; l++)
{
Refresh();
double X = 30;
double Y = 0;
for (double x = 0; x <= 510; x += o)
{
double y = Math.Sin((x + n + l) / 180 * Math.PI) * m;
g1.DrawLine(p, (float)X, (float)Y + 110, (float)(x / 1.8) + 30, (float)y + 110);
X = x / 1.8 + 30;
Y = y;
}
Thread.Sleep(100);
}
}
private void button2_Click(object sender, EventArgs e)
{
b = false;
pictureBox1.Refresh();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox3.Items.Add(comboBox3.Text);
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.Items.Add(comboBox2.Text);
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.Items.Add(comboBox1.Text);
}
}
}

private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
SolidBrush sb = new SolidBrush(Color.Black);//话刷
Graphics g = e.Graphics;
Pen p = new Pen(Color.Black, 1);
Point[] xpts = new Point[3] {
new Point(410 - 35, 108),
new Point(410 - 35, 112),
new Point(410 - 30, 110)
};
g.DrawLine(p, 30, 110, 410 - 30, 110);
g.DrawPolygon(p, xpts);
g.DrawString("X", new Font("宋体", 9), sb, 410 - 25, 105);
Point[] ypts = new Point[3] {
new Point(28, 25),
new Point(30, 20),
new Point(32, 25) };
g.DrawLine(p, 30, 232 - 30, 30, 20);
g.DrawPolygon(p, ypts);
g.DrawString("Y", new Font("宋体", 9), sb, 15, 20);
Graphics g1 = this.pictureBox1.CreateGraphics(); //创建画板,这里的画板是由pictureBox提供的.
int o = int.Parse(comboBox2.Text);
int n = int.Parse(comboBox3.Text);
int m = int.Parse(comboBox1.Text);
if (b != true) return;
double X = 30;
double x = 0;
double Y = 0;
for (int l = 0; l <= 720; l++)
{
if (b ==true)
this.Refresh();//这里我一直搞不懂
for (x = 0; x <= 510; x += o)
{
double y = Math.Sin((x+l + n) / 180 * Math.PI) * m;
g1.DrawLine(p, (float)X, (float)Y + 110, (float)(x / 1.8) + 30, (float)y + 110);
X = x / 1.8 + 30;
Y = y;
}
Thread.Sleep(10);
}
}
