form1.cs
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.Windows.Forms;
namespace XNAGame_007
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//窗体paint事件
//方法写在按钮事件中,当窗体图形被其他窗体遮盖,或者最小化,图形就消失了
private void button1_Click(object sender, EventArgs e)
{
Graphics g1 = this.CreateGraphics();
Pen pen1 = new Pen(Color.Blue);
SolidBrush brush1 = new SolidBrush(Color.Red);
int top = 30;
int left = 30;
int width = 50;
int height = 50;
g1.DrawEllipse(pen1, top, left, width, height);
g1.FillEllipse(brush1, top, left, width, height);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g1 = this.CreateGraphics();
Pen pen1 = new Pen(Color.Blue);
SolidBrush brush1 = new SolidBrush(Color.Red);
int top = 100;
int left = 100;
int width = 50;
int height = 50;
g1.DrawEllipse(pen1, top, left, width, height);
g1.FillEllipse(brush1, top, left, width, height);
}
}
}