Results 1 to 8 of 8

Thread: [RESOLVED] [VB6] - How use Paint event?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Resolved [RESOLVED] [VB6] - How use Paint event?

    how can i use the Paint event on VB6?
    i have tried used before but with some problems on showing the image.
    i know that the Refresh method is for call the Paint event. but i never use the Paint event with sucess. can anyone advice me?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6] - How use Paint event?

    Are you using something to loop, such as a Do...Loop, or a Timer? Or is it just to display one frame? Paint should fire no matter what, and gets fired after Form_Load() has taken place. Personally I don't like using Refresh cause it's very slow. I only use it if it's highly needed. If you can, could you post the code you currently have so I may see what you are trying to achieve?

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - How use Paint event?

    Quote Originally Posted by Jacob Roman View Post
    Are you using something to loop, such as a Do...Loop, or a Timer? Or is it just to display one frame? Paint should fire no matter what, and gets fired after Form_Load() has taken place. Personally I don't like using Refresh cause it's very slow. I only use it if it's highly needed. If you can, could you post the code you currently have so I may see what you are trying to achieve?
    sorry.. these is about Graphics(not games). and in these case is a frame with some if's conditions. and that if's depends on commands.
    i have 1 sub that must be called every time that we change 1 property, but i need the best choice for speed up my code
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6] - How use Paint event?

    I know it's not about games.

    Are you using Bitblt or TransparentBlt by any chance?

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - How use Paint event?

    Quote Originally Posted by Jacob Roman View Post
    I know it's not about games.

    Are you using Bitblt or TransparentBlt by any chance?
    TransparentBlt() is the best, because i need take off the backcolor
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6] - How use Paint event?

    Here ya go This assumes you loaded a pic already into Picture1

    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
    4.  
    5. Private Sub Form_Load()
    6.    
    7.     'Assuming you got a pic loaded
    8.     Picture1.AutoSize = True
    9.     Picture1.AutoRedraw = True
    10.     Picture1.Visible = False
    11.     Picture1.ScaleMode = vbPixels
    12.     frmMain.ScaleMode = vbPixels
    13.    
    14. End Sub
    15.  
    16. Private Sub Form_Paint()
    17.  
    18.     DoEvents
    19.     TransparentBlt frmMain.hdc, 0, 0, 200, 200, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, RGB(0, 0, 0)
    20.  
    21. End Sub

    And it works without a hitch.

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,964

    Re: [VB6] - How use Paint event?

    Quote Originally Posted by Jacob Roman View Post
    Here ya go This assumes you loaded a pic already into Picture1

    vb Code:
    1. Option Explicit
    2.  
    3. Private Declare Function TransparentBlt Lib "msimg32.dll" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal crTransparent As Long) As Boolean
    4.  
    5. Private Sub Form_Load()
    6.    
    7.     'Assuming you got a pic loaded
    8.     Picture1.AutoSize = True
    9.     Picture1.AutoRedraw = True
    10.     Picture1.Visible = False
    11.     Picture1.ScaleMode = vbPixels
    12.     frmMain.ScaleMode = vbPixels
    13.    
    14. End Sub
    15.  
    16. Private Sub Form_Paint()
    17.  
    18.     DoEvents
    19.     TransparentBlt frmMain.hdc, 0, 0, 200, 200, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, RGB(0, 0, 0)
    20.  
    21. End Sub

    And it works without a hitch.
    now i see my problem: the DoEvents method
    now i can change the properties allways and the image is showed updated
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    Elite Hacker Jacob Roman's Avatar
    Join Date
    Aug 2004
    Location
    Miami Beach, FL
    Posts
    5,349

    Re: [VB6] - How use Paint event?

    Np

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