using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace testdraw
{
public partial class Form1 : Form
{
protected Bitmap cBmp = new Bitmap(200, 200); //创建画布
protected Graphics cGraphic;
protected Color[] cColor = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Gray, Color.LightCoral, Color.Gold };
protected Pen cPen;
protected SolidBrush cSolidBrush;
protected Point[] cPoints;
protected int RowNum = 3; //扇区块数
protected int i = 0;
protected int j = 0;
protected int cAngle = 0;
protected int tmp = 0;
protected int xCircleCenter = 100;
protected int yCircleCenter = 100; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
try
{
cGraphic = Graphics.FromImage(cBmp);
cGraphic.Clear(Color.Snow); for (j = 0; j < RowNum; j++)
{
cAngle = 90;//扇区角度
cPen = new Pen(cColor[j], 3);
cSolidBrush = new SolidBrush(cColor[j]);
for (i = tmp; i < tmp + cAngle; i++)
{
cPoints[i - tmp] = new Point();
cPoints[i - tmp].X = (int)(1 - System.Math.Sin(i / 360 * 2 * System.Math.PI)) * (xCircleCenter - 30) + 10;
cPoints[i - tmp].Y = (int)(1 - System.Math.Cos(i / 360 * 2 * System.Math.PI)) * (yCircleCenter - 30) + 10; }
//加入圆心坐标点
cPoints[cAngle + 1] = new Point();
cPoints[cAngle + 1].X = xCircleCenter - 20;
cPoints[cAngle + 1].Y = yCircleCenter - 20; cPen = new Pen(cColor[j], 3);
cSolidBrush = new SolidBrush(cColor[j]);
cGraphic.DrawPolygon(cPen, cPoints);
cGraphic.FillPolygon(cSolidBrush, cPoints);
tmp += cAngle;
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
pictureBox1.Image = cBmp;
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace testdraw
{
public partial class Form1 : Form
{
protected Bitmap cBmp = new Bitmap(200, 200); //创建画布
protected Graphics cGraphic;
protected Color[] cColor = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Gray, Color.LightCoral, Color.Gold };
protected Pen cPen;
protected SolidBrush cSolidBrush;
protected Point[] cPoints;
protected int RowNum = 3; //扇区块数
protected int i = 0;
protected int j = 0;
protected int cAngle = 0;
protected int tmp = 0;
protected int xCircleCenter = 100;
protected int yCircleCenter = 100; public Form1()
{
InitializeComponent();
} private void Form1_Load(object sender, EventArgs e)
{
try
{
cGraphic = Graphics.FromImage(cBmp);
cGraphic.Clear(Color.Snow); for (j = 0; j < RowNum; j++)
{
cAngle = 90;//扇区角度
cPen = new Pen(cColor[j], 3);
cSolidBrush = new SolidBrush(cColor[j]);
for (i = tmp; i < tmp + cAngle; i++)
{
cPoints[i - tmp] = new Point();
cPoints[i - tmp].X = (int)(1 - System.Math.Sin(i / 360 * 2 * System.Math.PI)) * (xCircleCenter - 30) + 10;
cPoints[i - tmp].Y = (int)(1 - System.Math.Cos(i / 360 * 2 * System.Math.PI)) * (yCircleCenter - 30) + 10; }
//加入圆心坐标点
cPoints[cAngle + 1] = new Point();
cPoints[cAngle + 1].X = xCircleCenter - 20;
cPoints[cAngle + 1].Y = yCircleCenter - 20; cPen = new Pen(cColor[j], 3);
cSolidBrush = new SolidBrush(cColor[j]);
cGraphic.DrawPolygon(cPen, cPoints);
cGraphic.FillPolygon(cSolidBrush, cPoints);
tmp += cAngle;
}
}
catch (Exception exp)
{
MessageBox.Show(exp.Message);
}
pictureBox1.Image = cBmp;
}
}
}
解决方案 »
- C#执行sqcmd.ExecuteNonQuery() 报错
- BackgroundWorker调用控件的方法?
- 请问提供加密前和加密后的字符串, 能否推出加密算法?
- byte[4]转化为float
- mdi最大化时屏幕不够显示,如果调出垂直滚动条?
- 各位大虾们请进,求房地产销售软件源代码
- 请帮我改一个存储过程 存储过程有缺陷. 用来生成表的 insert 脚本的 急!!! 谢谢各位
- 简单问题 怎样在c#中修改DBgrid的列标题。我已经建立了一个dataset 但是不知道怎样修改列的默认的label
- 问一个关于正则表达式的问题!
- 高分求解:如何在代码中将文本框绑定到dataSet中某个表的某个字段?
- C#中如何将多页pdf文件中的每一页转换成为相应的JPEG图片
- c# 获取另一窗体textbox的值
提示这句有问题,"未将对象引用设置到对象的实例"
cPoints[i - tmp]=new Point[i - tmp];
cGraphic = Graphics.FromImage(cBmp);
cGraphic.Clear(Color.Snow); cAngle = 90;//扇区角度
cPoints = new Point[cAngle * RowNum]; for (j = 0; j < RowNum; j++)
{
cPen = new Pen(cColor[j], 3);
cSolidBrush = new SolidBrush(cColor[j]);
for (i = tmp; i < tmp + cAngle; i++)
{另外,你这个程序毛病还有很多很多
比如除法如果是用int来除的话,返回的也是整形
应该
cPoints[i - tmp].X = (int)(1 - System.Math.Sin((float)i / (float)360) * 2 * System.Math.PI) * (xCircleCenter - 30) + 10;
还有,圆心和圆周的坐标不要用同一个数组。
另外你圆周坐标的计算方法也有点问题,数学的问题你自己看看吧。
cPoints[i - tmp].X = (int)((1 - System.Math.Sin((float)i / (float)360 * 2 * System.Math.PI)) * (xCircleCenter - 30)) + 10;
cPoints[i - tmp].Y = (int)((1 - System.Math.Cos((float)i / (float)360 * 2 * System.Math.PI)) * (xCircleCenter - 30)) + 10;
以上是画点的坐标