Re: Weird problem when re-painting form while moving it outside of the screen!
- From: "Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx>
- Date: Wed, 28 Sep 2005 19:41:07 -0400
You can only paint what is actually visible on the screen.
If you want to determine what portion of your control is visible,
use RectVisible to determine if any part of the control is in the
screen's clipping region.
<theunissen@xxxxxxxxxxx> wrote in message
news:1127947673.008641.26930@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Hi,
>
> I've been struggling with this problem for days on and off. Hopefully
> somebody has some insight in this. I have a usercontrol which is placed
> on a form. When the control gets the paint event, I use a memory bitmap
> to draw on and then blit it back to the original DC (from the
> graphics).
>
> The problem is that when moving the form out of the screen and moving
> it back into the screen view. the control receives paint events and the
> clipping rectangle is correct, however nothing gets updated
> appropriately. When the control receives the paint events while inside
> the screen area everything is blitted fine.
>
> I have set the styles for the control as follows:
> MyBase.SetStyle(ControlStyles.AllPaintingInWmPaint, True)
> MyBase.SetStyle(ControlStyles.DoubleBuffer, False)
> MyBase.SetStyle(ControlStyles.Opaque, True)
> MyBase.SetStyle(ControlStyles.ResizeRedraw, True)
>
>
> And the code for the paint event is as follows:
>
> Private Sub m_Control_Paint(ByVal sender As Object, ByVal e As
> System.Windows.Forms.PaintEventArgs) Handles m_Control.Paint
> 'Get original hdc
> Dim hdcWindow As Integer = e.Graphics.GetHdc().ToInt32
>
> 'Create a compatible DC with the one given to us
> Dim hdcMemory As Integer = CreateCompatibleDC(hdcWindow)
>
> 'Create a compatible bitmap in memory DC with the size of the
> clipping rectangle
> Dim hMemoryBitmap As Integer = CreateCompatibleBitmap(hdcWindow,
> e.ClipRectangle.Width, e.ClipRectangle.Height)
>
> 'Select the new bitmap into memory DC
> Dim hMemoryBitmapOld As Integer = SelectObject(hdcMemory,
> hMemoryBitmap)
>
> 'Clear the memory DC
> BitBlt(hdcMemory, e.ClipRectangle.X, e.ClipRectangle.Y,
> e.ClipRectangle.Width, e.ClipRectangle.Height, hdcMemory,
> e.ClipRectangle.X, e.ClipRectangle.Y, WHITENESS)
>
> 'cOPY the memory bitmap back to the real DC.
> BitBlt(hdcWindow, e.ClipRectangle.X, e.ClipRectangle.Y,
> e.ClipRectangle.Width, e.ClipRectangle.Height, hdcMemory,
> e.ClipRectangle.X, e.ClipRectangle.Y, SRCCOPY)
>
> 'Select the original bitmap back into the DC
> SelectObject(hdcMemory, hMemoryBitmapOld)
>
> 'Delete the compatible bitmap
> DeleteObject(hMemoryBitmap)
>
> 'Delete the compatible DC
> DeleteDC(hdcMemory)
>
> 'Release the DC
> e.Graphics.ReleaseHdc(New IntPtr(hdcWindow))
> End Sub
>
>
> Once again, everything works fine, as long as the form is inside the
> screen area!
>
> Thanks in advance.
>
.
- Follow-Ups:
- References:
- Prev by Date: Re: Weird problem when re-painting form while moving it outside of the screen!
- Next by Date: Re: Weird problem when re-painting form while moving it outside of the screen!
- Previous by thread: Re: Weird problem when re-painting form while moving it outside of the screen!
- Next by thread: Re: Weird problem when re-painting form while moving it outside of the screen!
- Index(es):
Relevant Pages
|