菜鸟求问,这个程序怎么在vs2010下编译通过呢???
namespace 简单画图板{
public partial class Form1 : Form
{
private Bitmap bitmap;
private Pen pen = new Pen(Color.Black);
private int choice = 0;
private SolidBrush sBrush;
private int x1, y1, x2, y2;
private int count = 0;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
bitmap = new Bitmap(panel1.Width, panel1.Height);//新建位图
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
choice = 0;
count = 0;
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
choice = 1;
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
choice = 2;
}
private void radioButton4_CheckedChanged(object sender, EventArgs e)
{
choice = 3;
}
private void radioButton5_CheckedChanged(object sender, EventArgs e)
{
choice = 4;
}
private void radioButton6_CheckedChanged(object sender, EventArgs e)
{
choice = 5;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
ColorDialog colorDialog = new ColorDialog();
colorDialog.AllowFullOpen = true;
colorDialog.FullOpen = false;
if (colorDialog.ShowDialog() == DialogResult.OK)
{
pen = new Pen(colorDialog.Color);
sBrush = new SolidBrush(colorDialog.Color);
pictureBox1.BackColor = colorDialog.Color;
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
pen.Color = pictureBox1.BackColor;
switch (choice)
{
case 0://画直线
count++;
if (count % 2 != 0) { x1 = e.X; y1 = e.Y; }
else
{
x2 = e.X; y2 = e.Y;
line(x1, y1, x2, y2);
}
break;
case 1://画圆弧
x1 = e.X; y1 = e.Y;
circular(x1, y1, Convert.ToInt32(textBox1.Text));
break;
case 2://画椭圆
x1 = e.X; y1 = e.Y;
ellipse(x1, y1, Convert.ToInt32(textBox2.Text), Convert.ToInt32(textBox3.Text));
break;
case 3://画多边形
count++;
if (count == 1) { x2 = e.X; y2 = e.Y; }
else
{
x1 = x2; y1 = y2; x2 = e.X; y2 = e.Y;
line(x1, y1, x2, y2);//直接调用画直线的算法
}
break;
case 4://颜色填充
x1 = e.X; y1 = e.Y;
Color old_color = getpixel(x1, y1);
Color new_color = pictureBox1.BackColor;
flood_fill_4(x1, y1, old_color, new_color,0);
break;
case 5://阴影填充
x1 = e.X; y1 = e.Y;
old_color = getpixel(x1, y1);
new_color = pictureBox1.BackColor;
shade(x1, y1, old_color, new_color);
break;
}
}
private void panel1_MouseLeave(object sender, EventArgs e)
{
count = 0;//鼠标离开画图区,count清零
}
private void clr_img_Click(object sender, EventArgs e)//清除图像
{
panel1.Refresh();//刷新panel
bitmap = new Bitmap(panel1.Width, panel1.Height);//重绘bitmap
}
/*重绘位图*/
private void draw()
{
Graphics g = panel1.CreateGraphics();
g.DrawImage(bitmap, 0, 0);
}
/*设置像素颜色*/
private void drawpixel(int x, int y, Pen pen)
{
if (x > 0 && x < panel1.Width && y > 0 && y < panel1.Height)
{
bitmap.SetPixel(x, y, pen.Color);
}
}
/*获得像素颜色*/
private Color getpixel(int x, int y)
{
Color clr = Color.Black;
if (x > 0 && x < panel1.Width && y > 0 && y < panel1.Height)
{
clr = bitmap.GetPixel(x, y);
}
return clr;
}
/*画直线Bresenham算法*/
public void line(int x1, int y1, int x2, int y2)
{
int x, y, dx, dy, e;
dx = Math.Abs(x1 - x2);
dy = Math.Abs(y1 - y2);
if (dx >= dy)
{
e = -dx; x = x1; y = y1;
for (int i = 0; i < dx; i++)
{
drawpixel(x, y, pen);
if (x1 <= x2)
{
x++;
}
else
{
x--;
}
e = e + 2 * dy;
if (e >= 0)
{
if (y1 <= y2)
{
y++;
}
else
{
y--;
}
e = e - 2 * dx;
}
}
}
else
{
e = -dy; x = x1; y = y1;
for (int i = 0; i < dy; i++)
{
drawpixel(x, y, pen);
if (y1 <= y2)
{
y++;
}
else
{
y--;
}
e = e + 2 * dx;
if (e >= 0)
{
if (x1 <= x2)
{
x++;
}
else
{
x--;
}
e = e - 2 * dy;
}
}
}
draw();
}
/*画圆弧Bresenham算法*/
public void circular(int x1, int y1, int r)
{
int x, y, d;
x = 0; y = r; d = 3 - 2 * r;
while (x < y)
{
/*画对称点*/
drawpixel(x1 + x, y1 + y, pen);
drawpixel(x1 + y, y1 + x, pen);
drawpixel(x1 + x, y1 - y, pen);
drawpixel(x1 + y, y1 - x, pen);
drawpixel(x1 - x, y1 + y, pen);
drawpixel(x1 - y, y1 + x, pen);
drawpixel(x1 - x, y1 - y, pen);
drawpixel(x1 - y, y1 - x, pen);
if (d < 0)
d = d + 4 * x + 6;
else
{
d = d + 4 * (x - y) + 10;
y--;
}
x++;
}
if (x == y)
/*画对称点*/
drawpixel(x1 + x, y1 + y, pen);
drawpixel(x1 + y, y1 + x, pen);
drawpixel(x1 + x, y1 - y, pen);
drawpixel(x1 + y, y1 - x, pen);
drawpixel(x1 - x, y1 + y, pen);
drawpixel(x1 - y, y1 + x, pen);
drawpixel(x1 - x, y1 - y, pen);
drawpixel(x1 - y, y1 - x, pen);
draw();
}
/*画椭圆*/
public void ellipse(int x1, int y1, int a, int b)
{/* 椭圆中心在(x1,y1),长半轴为a,短半轴为b */
int x, y, d, P_x, P_y, S_a, S_b;
S_a = a * a;
S_b = b * b;
P_x = (int)(0.5 + (float)S_a / Math.Sqrt((float)(S_a + S_b)));
P_y = (int)(0.5 + (float)S_b / Math.Sqrt((float)(S_a + S_b)));
/* 生成第一象限内的上半部分椭圆弧 */
x = 0;
y = b;
d = 4 * (S_b - b * S_a) + S_a;
/*画对称点*/
drawpixel(x1 + x, y1 + y, pen);
drawpixel(x1 + x, y1 - y, pen);
drawpixel(x1 - x, y1 + y, pen);
drawpixel(x1 - x, y1 - y, pen);
while (x <= P_x)
{
if (d <= 0)
d += 4 * S_b * (2 * x + 3);
else
{
d += 4 * S_b * (2 * x + 3) - 8 * S_a * (y - 1);
y--;
}
x++;
/*画对称点*/
drawpixel(x1 + x, y1 + y, pen);
drawpixel(x1 + x, y1 - y, pen);
drawpixel(x1 - x, y1 + y, pen);
drawpixel(x1 - x, y1 - y, pen);
}
/* 生成第一象限内的上半部分椭圆弧 */
x = a;
y = 0;
d = 4 * (S_a - a * S_b) + S_b;
/*画对称点*/
drawpixel(x1 + x, y1 + y, pen);
drawpixel(x1 + x, y1 - y, pen);
drawpixel(x1 - x, y1 + y, pen);
drawpixel(x1 - x, y1 - y, pen);
while (y < P_y)
{
if (d <= 0)
d += 4 * S_a * (2 * y + 3);
else
{
d += 4 * S_a * (2 * y + 3) - 8 * S_b * (x - 1);
x--;
}
y++;
/*画对称点*/
drawpixel(x1 + x, y1 + y, pen);
drawpixel(x1 + x, y1 - y, pen);
drawpixel(x1 - x, y1 + y, pen);
drawpixel(x1 - x, y1 - y, pen);
}
draw();
}
/*颜色填充*/
private void flood_fill_4(int x, int y, Color old_color, Color --------------------编程问答-------------------- 编译不通过的原因是什么啊? --------------------编程问答-------------------- 写大神回复。其实我是不知道该怎么编译C#程序,在VS2010环境下 --------------------编程问答-------------------- 解决方案资源管理器->项目上鼠标右键->生成 或者 按F6 --------------------编程问答--------------------
补充:.NET技术 , C#