我想在Tabpage上使用GDI绘图,经查询,使用过下面两种方法:
一、
private void Form1_Load(object sender, EventArgs e)
{
TabPage1.Paint += TabPage1_Paint;
}
private void TabPage1_Paint(object sender, EventArgs e)
{
Graphics graphics = this.CreateGraphics();
Pen myPen = new Pen(Color.Red, 10);
graphics.DrawLine(myPen, 0, 400, 1000, 400);
}
二、
private void Form1_Load(object sender, EventArgs e)
{
TabPage1.Paint += TabPage1_Paint;
}
protected override void OnPaint(PaintEventArgs e)//重写OnPaint方法
{
base.OnPaint(e);//先执行基类的OnPaint方法
Graphics graphics = e.Graphics;
Pen mypen = new Pen(Color.Red, 10);
graphics.DrawLine(mypen, 0, 400, 100, 400);
}
所得结果均会被遮挡,无法在tabpage上显示,请问正确的做法应是什么呢?
初学者,请大神们指教!