Onpaint()和paint事件的问题

netfox2003 2008-06-01 01:28:34
为什么重写Onpaint方法没有激发paint事件呢?

protected override void OnPaint(PaintEventArgs e)
{

base.OnPaint(e);
//Form1_Paint(e, e);
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y,(int)(m_Bitmap.Width), (int)(m_Bitmap.Height)));
}
...全文
79 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
netfox2003 2008-06-01
  • 打赏
  • 举报
回复
OK,行了,谢了
minioreo 2008-06-01
  • 打赏
  • 举报
回复
namespace TestOnPaint
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.Paint += new PaintEventHandler(Form1_Paint);
}

void Form1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Chocolate, ClientRectangle);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
}

minioreo 2008-06-01
  • 打赏
  • 举报
回复
给出完整代码吧
netfox2003 2008-06-01
  • 打赏
  • 举报
回复
没这句的base.OnPaint(e); 但问题还末解决,补充说明一下,在前面我已用了this.Invalidate();
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y,(int)(m_Bitmap.Width), (int)(m_Bitmap.Height)));
}
minioreo 2008-06-01
  • 打赏
  • 举报
回复
private void Form1_Paint(object sender, PaintEventArgs e) 
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.DrawImage(m_Bitmap, new Rectangle(this.AutoScrollPosition.X, this.AutoScrollPosition.Y,(int)(m_Bitmap.Width), (int)(m_Bitmap.Height)));
}


这个方法里为何要调用base.OnPaint(e) 岂不是把所有事件又执行一遍 会出问题的吧

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧