drawingarea question

Post your Gambas programming questions here.
Post Reply
bill-lancaster
Posts: 190
Joined: Tuesday 26th September 2017 3:17pm
Location: NW England

drawingarea question

Post by bill-lancaster »

Why is the DrawingArea1_Draw call executed several times?
A simple form with DrawingArea1 on it
and

Code: Select all

Public Sub DrawingArea1_Draw()
Draw.Text("XXXX",10,10,20,20)
End
is executed 5 times
User avatar
cogier
Site Admin
Posts: 1118
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: drawingarea question

Post by cogier »

Very interesting. I am not sure why, but it drops to 3 if you use Paint instead of draw (now depricated).

Try this code and then resize the Form. It will be in the hundreds in no time.

Sorry, I don't know why this happens, I can only guess this is due to the Form arranging its items.
iCount As Integer
DrawingArea1 As DrawingArea
HBox1 As Hbox
Label1 As Label

Public Sub Form_Open()

  With Me
    .Arrangement = Arrange.Vertical
    .H = 500
    .W = 700
    .Padding = 5
  End With

  With DrawingArea1 = New DrawingArea(Me) As "DrawingArea1"
    .Expand = True
  End With

  With HBox1 = New HBox(Me)
    .H = 56
    .W = 100
    .Invert = True
  End With

  With Label1 = New Label(HBox1) As "Label1"
    .H = 56
    .W = 100
    .Expand = True
    .Font.Bold = True
    .Font.Size = 36
    .Alignment = Align.Center
  End With

End

Public Sub DrawingArea1_Draw()

  Inc iCount
  Label1.Text = Str(iCount)
  Paint.begin(DrawingArea1)
  Paint.Text("XXXX", 10, 10, 20, 20)
  Paint.Stroke
  Paint.End

End
Post Reply