Re: Weird problem when re-painting form while moving it outside of the screen!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
>


.



Relevant Pages

  • Re: Picture control max size?
    ... I said that the memory limitation applies to a screen compatible memory DC and an associated screen compatible memory bitmap, whether the bitmap is created using an Autoredraw VB Picture Box or using the equivalent API functions. ... I went on to say that these limitations do NOT apply to a bitmap that is device independent (a DIBSection, for example) because DIBSections automatically use whatever memory is available, including pagefile memory on the disk, and can therefore be very large indeed. ... The chances are that the control to which you refer uses DIBSections or something similar. ...
    (microsoft.public.vb.general.discussion)
  • Re: Simulate Autoredraw
    ... Not sure what you mean by "copied to the picturebox during each paint ... as I only have to assign the bitmap to the control image property and forget ... Assigning the bitmap to the image property seems to work fine... ...
    (microsoft.public.dotnet.languages.vb)
  • Drawing Icons and BitMaps
    ... I have a user control that I paint myself. ... I have a bitmap in the control ... The first time I paint an Icon, it works ok but when I refresh the control ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: GDI+ to draw on canvas with alpha channel
    ... If you want to know whether we can draw on a memory DC with alpha value, ... I want to paint an EMF (not really ... over any other bitmap. ...
    (microsoft.public.win32.programmer.gdi)
  • Re: GDI+ Graphics Dump
    ... the control to paint itself onto a blank canvas in memory, ...
    (microsoft.public.dotnet.languages.vb)