运行后没有图像!谢谢!
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace basicgraphic
{
public partial class frmMain : Form
{
int fg;
public frmMain()
{
InitializeComponent();
}
private void btnClear_Click(object sender, EventArgs e)
{
fg = 0;
this.Invalidate();
}
private void btnCir_Click(object sender, EventArgs e)
{
fg = 1;
this.Invalidate();
}
private void btnEllipse_Click(object sender, EventArgs e)
{
fg = 2;
this.Invalidate();
}
private void btnPie_Click(object sender, EventArgs e)
{
fg = 3;
this.Invalidate();
}
private void btnLine_Click(object sender, EventArgs e)
{
fg = 4;
this.Invalidate();
}
private void btnArc_Click(object sender, EventArgs e)
{
fg = 5;
this.Invalidate();
}
private void btn_Click(object sender, EventArgs e)
{
fg = 6;
this.Invalidate();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
Graphics g = this.CreateGraphics();
Pen pen1 = new Pen(Color.Blue, 3);
switch (fg)
{
case 0:
g.Clear(Color.Gainsboro);
break;
case 1:
g.DrawEllipse(pen1, 50, 50, 150, 150);
break;
case 2:
g.DrawEllipse(pen1, 50, 50, 300, 200);
break;
case 3:
g.DrawLine(pen1, 50, 100, 300, 100);
break;
case 4:
g.DrawArc(pen1, 50, 50, 200, 300, 180, 90);
break;
case 5:
g.DrawRectangle(pen1, 50, 50, 200, 150);
break;
case 6:
g.DrawPie(pen1, 100, 100, 300, 200, 225, 90);
break;
}
}
}
}
windows应用程序 7个Button 1.btnClear 清除2.btnCir 圆 3.btnEllipse 椭圆 4.benPie扇形 5.btnLine 直线6.btnArc弧线 7.btn矩形
还有我自己加了个panel..书本没的!还有private void panel1_Paint(object sender, PaintEventArgs e) 书本这句是
private void femMain_Paint(object sender, PaintEventArgs e)
生成成功..却运行不出图像!点解!