//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.Windows.Forms;
namespace CSharpForm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//在Form的构造函数中画图,只执行一次,当最小化后消失
/* Graphics dc = this.CreateGraphics();
Show();
Pen bluePen = new Pen(Color.Blue, 3);
dc.DrawRectangle(bluePen, 0, 0, 50, 50);
Pen redPen = new Pen(Color.Red, 2);
dc.DrawEllipse(redPen, 0, 50, 80, 60);
*/
}
//重写OnPaint函数来画图,最小化不消失
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics dc = e.Graphics;
Pen bluePen = new Pen(Color.Blue, 3);
dc.DrawRectangle(bluePen, 0, 0, 50, 50);
Pen redPen = new Pen(Color.Red, 2);
dc.DrawEllipse(redPen, 0,50,80,60);
}
}
}
C#简单画图,构造函数画图和OnPaint函数画图
最新推荐文章于 2024-07-06 22:39:10 发布