[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?
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?
Re: [VB6] - How use Paint event?
Quote:
Originally Posted by
Jacob Roman
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;)
Re: [VB6] - How use Paint event?
I know it's not about games. ;)
Are you using Bitblt or TransparentBlt by any chance?
Re: [VB6] - How use Paint event?
Quote:
Originally Posted by
Jacob Roman
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;)
Re: [VB6] - How use Paint event?
Here ya go ;) This assumes you loaded a pic already into Picture1
vb Code:
Option Explicit
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
Private Sub Form_Load()
'Assuming you got a pic loaded
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture1.Visible = False
Picture1.ScaleMode = vbPixels
frmMain.ScaleMode = vbPixels
End Sub
Private Sub Form_Paint()
DoEvents
TransparentBlt frmMain.hdc, 0, 0, 200, 200, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, RGB(0, 0, 0)
End Sub
And it works without a hitch.
Re: [VB6] - How use Paint event?
Quote:
Originally Posted by
Jacob Roman
Here ya go ;) This assumes you loaded a pic already into Picture1
vb Code:
Option Explicit
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
Private Sub Form_Load()
'Assuming you got a pic loaded
Picture1.AutoSize = True
Picture1.AutoRedraw = True
Picture1.Visible = False
Picture1.ScaleMode = vbPixels
frmMain.ScaleMode = vbPixels
End Sub
Private Sub Form_Paint()
DoEvents
TransparentBlt frmMain.hdc, 0, 0, 200, 200, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, RGB(0, 0, 0)
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
Re: [VB6] - How use Paint event?