protected override void OnPaint(PaintEventArgs e)
{
// Nothing here...
}
I wrote a class that inherits System.Windows.Forms.Form
. I overrode the method OnPaint
and do nothing in it, as shown above. I expected to see nothing appear on the screen when when I run the code, but the window appeared as usual.
I made sure that nothing got painted, yet it looks completely normal. Why did this happen?
The Form.OnPaint() method already does no painting at all. So you didn't change anything, the only thing you did is preventing the Paint event from getting fired by not calling base.OnPaint(). Not very useful of course.
You forgot about the other method that paints, the OnPaintBackground() method. It draws the background of the window as set by the BackColor property, an image if you've set the BackgroundImage property. OnPaint() and any Paint event handler draw on top of that. The fundamental cause of flicker.
Trying to channel why you are doing this: no, this is not the proper way to achieve transparency. An unpainted window shows random pixels, whatever happened to be present in the video frame buffer before the window was created. Which looks like transparency, but only for a very short time. Messed up when the user resizes or moves the window. Windows are fundamentally opaque. The proper way is to use the TransparencyKey property, it enables a mixer that combines the pixels of multiple windows. Also the way the Opacity property works.
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加