Neither Invalidate() nor Refresh() invokes OnPaint()
Posted
by user181813
on Stack Overflow
See other posts from Stack Overflow
or by user181813
Published on 2010-04-13T08:15:54Z
Indexed on
2010/04/13
8:23 UTC
Read the original article
Hit count: 405
I'm trying to get from Line #1 to Line #2 in the below code:
using System;
using System.Windows.Forms;
namespace MyNameSpace
{
internal class MyTextBox : System.Windows.Forms.TextBox
{
protected override void OnEnabledChanged(EventArgs e)
{
base.OnEnabledChanged(e);
Invalidate(); // Line #1 - can get here
Refresh();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
System.Diagnostics.Debugger.Break(); // Line #2 - can't get here
}
}
}
However, it seems that neiter Invalidate() nor Refresh() causes OnPaint(PaintEventArgs e) to be invoked. Two questions:
- Why doesn't it work?
- If it can't be fixed: I only want to invoke OnPaint(PaintEventArgs e) in order to access the e.Graphics object - is there any other way to do this?
© Stack Overflow or respective owner