[Gambas-user] Why is this code running twice?

Fabien Bodard gambas.fr at ...626...
Wed Aug 2 11:40:39 CEST 2017


Ok Fernando ... your code is no so bad :-)


First never call the resizing of the caneva in the drawing event as it
call itself the drawing event ... (normally if I rememember well it
have been disabled)
So you must resize in another place.

then I don't really understand why you are resizing the drawingarea
and not the windows... but you must have your idea.

You need to call DrawingArea.Refresh Function to force the refresh so
the _Draw event calling. Or resising the form, or anything else that
force the need to refresh the area.


For example if you want to make a clock you do :

'Where timer delay is 1000 for example
Public sub MyTimer_Timer()

$dCurTime = GetCurTime()
dwgClock.Refresh

End



==> the code revised

' Gambas class file

Private Const W As Integer = 2048
Private Const H As Integer = 2048

Public Sub _new()

    dwgArea.width = 800 ' does nothing
  dwgArea.Height = 1000 ' does nothing  Print dwgArea.width; dwgArea.Height
  dwgArea.Refresh
End



Public Sub DwgArea_Draw()

  Dim angle As Float
  Dim eScale As Float
  Dim i As Integer

  Print "Executing" & Now

  Paint.Translate(dwgArea.W / 2, dwgArea.H / 2)
  Paint.Brush = Paint.Color(Color.SetAlpha(Color.Red, 128))
  Paint.LineWidth = 1

  For i = -15 To 195 Step 15

    angle = Rad(CFloat(i))
    Paint.MoveTo(0, 0)
    Paint.LineTo(Cos(angle) * W / 2, Sin(angle) * H / 2)
    Print Cos(angle) * w / 2
    Paint.Stroke
    'Paint.Fill
  Next

End


Best Regards,

Fabien Bodard




More information about the User mailing list