Results 1 to 5 of 5

Thread: Using Picturebox as Buffer problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    65

    Using Picturebox as Buffer problem

    I have a group of labels and some shapes that are being animated (updated once very 20 ms or so). To reduce the flicker, I thought I would put them in a picturebox, and then just bitblt from the box to the form instead of showing the box.

    The problem I'm noticing now is this:

    If you bitblt from the box when it is not visible (or offscreen), it seems that only the background (and none of the controls) will appear on the form (after blting).

    The only way I can seem to get the controls to show up when I blt from the box is to have the box visible (which defeats the purpose of using it as a buffer).

    Is it possible to blt from an invisible picturebox and have the controls in the picturebox show up (not just the background)?

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Using Picturebox as Buffer problem

    I don't know if that is possible, hopefully somebody who knows will chime in.

    What I do know is that the "proper" way of drawing items yourself (using the .Print/.Line/.Circle/etc methods) rather than using controls will not have that problem, and will also not have flicker. Unfortunately it is likely to require a little more work.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2005
    Posts
    65

    Re: Using Picturebox as Buffer problem

    Yeah I've done buffering before, but I guess this time I was trying to be lazy because it was a fairly small project. I guess thats what I get for going cheap. I can replace the graphics by drawing them in, but what about the text?

    Is there a way to use Print (or something else) so I don't have to resort to API text? The only time I've ever used print it always just prints at 0,0 first and then goes down line by line. I would need to position the text.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Using Picturebox as Buffer problem

    As mentioned already, drawing them yourself may be optimal.

    But here is a way to BitBlt (sort of) from a non-visible picturebox with following restrictions

    1. The entire picturebox area is painted, can't just do part of it
    2. SendMessage vs BitBlt
    Code:
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByRef lParam As Any) As Long
    Private Const WM_PAINT As Long = &HF&
    
    Private Sub Command1_Click()
        SendMessage Picture1.hwnd, WM_PAINT, Picture2.hDC, ByVal 0&
    End Sub
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5
    Hyperactive Member
    Join Date
    Jul 2010
    Posts
    273

    Re: Using Picturebox as Buffer problem

    Is it possible to blt from an invisible picturebox and have the controls in the picturebox show up (not just the background)?
    When the container (your PictureBox in this case) is hidden, its contents (Labels and Shape, etc in this case) are hidden.

    It has all the merits to draw by yourself texts and shapes including lines. More flexible and simpler in coding, and better quality in results -- the appended images shall illustrate some of the points.

    Once drawn, you can BitBlt or StretchBlt even if the PictureBox is made invisible.
    Attached Images Attached Images  
    Last edited by petersen; Oct 20th, 2010 at 12:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width