就是重载窗体的OnPain方法,见下图
出现智能提示后,按【Tab】即可
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//重载后方法!
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawLine(Pens.Black, 10, 10, 100, 100);
}
}
}
重载OnPain方法后,每次窗体显示内容被更新时,就调用次方法来刷新窗体。