canvas problem

using canvas picture to display graphic objects (SkyMap) .
all the code is called from the canvas openEvent

  'Initialize the Canvas with default settings
  #If TargetWin32
     me.EraseBackground = False
     me.DoubleBuffer = True
     me.Transparent = true
     app.UseGDIPlus = True
  #Elseif TargetMacOS
  #ElseIf TargetLinux
  If PictureHeight = 0 then
    Call RunOnce
  end If
  Call Init
  Call DrawSky  // display the SkyMap in the canvas.

MouseMove (x,y)
 mX = X
 mY = Y
    If chkCurseur.Value = true Then
    'search the closest star to the cursor pointer
      Call HighLightStarFromCoord(g,mX,mY) return the starname inside the ring (pointer)

  end if    

The method HightLightFromCoordinates(g,mX,mY) is called from MouseMove event because cursor coordinates “mX” and “mY” are requested.
Then HightLightFromCoordinates(g,mX,mY) return the graphic “name of the star” pointed on canvas.
unfortunately nothing happened …
adding me.invalidate to HightLightFromCoordinates(g,mX,mY) the pointer appear and show the exact starname but the background (skyMap) disappears, canvass become transparent (white).

That’s roughly my problem.

Did you read System.MouseX and System.MouseY there: ?

Move all drawing code into the Paint event.

Paint Event

  'Draw the picture to the graphics layer
  If PBuffer <> Nil then
    g.DrawPicture(PBuffer,0,0,me.Width, me.Height, 0,0, PBuffer.Width, PBuffer.Height)
  End If
  'Draw a rectangle around the canvas
  g.DrawRect(0,0,me.Width, me.Height)
  PBuffer.Graphics.ClearRect(0, 0, PBuffer.Width, PBuffer.Height)

drawing code in DrawSky called from OpenEvent following picture :


all chkbox are running for drawing other graphic objects as ecliptic curve, celestial equator, constellations …
They use the same way as HighLightFromCoord() !

Remove PBuffer.Graphics.ClearRect.

Perfect, running …

I have tried to find this bug , as is shown on the screenshot, the first and second star are not unloaded from memory when cursor left, unlike the name wich is displayed in a Textfield (left top corner) , changed.
Any idea ?