Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing points in a Picture control

Status
Not open for further replies.

nhungr

Programmer
Jan 31, 2005
26
CA
Hello.

I am trying to draw points in a Picture control overtop of an image. I initially load an image into an Image control that I've placed inside the Picture boundaries. Then I stretch the image to the size of the Picture control. Then I run a loop that should draw a set of points every few seconds OVERTOP of the image. For drawing the points, I use the Picture1.Circle function.

However, when the loop runs, the whole image flickers and the points are hidden behind the image control. I've tried setting the Image's Zorder to 1, but I don't know what else to do.

Can anyone help me? Thanks alot,

Nikolai.

 
Set the Picture control's AutoRedraw property to False.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
I've already tried that! And there's no change???
 
I put my code in a Timer control and have it draw a circle every second, and it works fine:

Private Sub Timer1_Timer()
Static px As Integer
Static py As Integer

px = px + 100
py = py + 100

If px > Picture1.Width Or py > Picture1.Height Then Timer1.Enabled = False

Picture1.Circle (px, py), 50, vbBlack

End Sub

If I have AutoRedraw set to True, I get the behavior you describe - the picture flickers and I can occasionally see the circles underneath the Image control as it flickers. If I set the AutoRedraw property to False, the flickering stops and the circles draw on top of the Image control.

Could you post your code that draws the circles?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson
 
Here's a very simplified version of my drawing code. The Picture's Autoredraw is set to False. Note that the call to TimeStepLoop is actually a call to a function in a DLL library that I created in C++. This function loops through some calculations and returns the set of X and Y coordinates for the points and updates the timestep. I don't think the problem lies with this call.

Keep in mind that I'm using an Image control within the Picture control because it is stretchable, unlike the Picture control! I hope this makes sense, and thanks alot for any further suggestions!

Code:
Private Sub RunButton_Click()
   Call ScaleImage
   cancelerror = 0 [COLOR=green]'can be set to 1 by user input[/color]
   Do
       TimeStepLoop [COLOR=red]... X, Y, and Time variables ...[/color]  [COLOR=green]'Call to a DLL library created in C++ [/color]
       Call DrawPoints(Xold(), Yold(), vbBlack)
       Call DrawPoints(Xnew(), Ynew(), vbRed)
       DoEvents
   Loop While ((cancelerror = 0) And (STOPFLAG = False)) [COLOR=green] 'Loop while user doesn't cancel process [/color]
End Sub


Sub ScaleImage()
   Form.Image1.Visible = False
   Form.Image1.Left = Form.Picture1.ScaleLeft
   Form.Image1.Width = Abs(Form.Picture1.ScaleWidth)
   Form.Image1.Top = Form.Picture1.ScaleTop
   Form.Image1.Height = Abs(Form.Picture1.ScaleHeight)
   Form.Image1.Visible = True
   Form.Image1.Enabled = False
   Form.Image1.ZOrder 1
End Sub


Sub DrawPoints(X() As Double, Y() As Double, colour As ColorConstants)
   For i = 0 To 2000
       DAN3D_Pics.Picture1.Circle (X(i), Y(i)), 5, colour
   Next i
End Sub
 
Private Sub RunButton_Click()
Call ScaleImage
Picture1.Refresh
cancelerror = 0 'can be set to 1 by user input
Do
TimeStepLoop ... X, Y, and Time variables ... 'Call to a DLL library created in C++
Call DrawPoints(Xold(), Yold(), vbBlack)
Call DrawPoints(Xnew(), Ynew(), vbRed)
DoEvents
Loop While ((cancelerror = 0) And (STOPFLAG = False)) 'Loop while user doesn't cancel process
End Sub
 
That's it, you solved it!!!! Thank you very much. I knew it had to be some simple one-liner. I want to star your post, but my browser doesn't respond to the "Thank you" link for some reason. So thanks anyway...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top