I am using Reflection to measure a label text width.
If I don't put in a Doevents, (see below), the returned value is random or "previous" value from prior calls.
Is there a better (non-Doevents) way to get this to work consistently?
Thanks,
Rusty
The code is as below.
If I don't put in a Doevents, (see below), the returned value is random or "previous" value from prior calls.
Is there a better (non-Doevents) way to get this to work consistently?
Thanks,
Rusty
The code is as below.
B4X:
'MAIN inline code, Label1 is loaded in a .bal layout
Type CameraSize (Width As Int, Height As Int)
...
Label1.Text = "yes"
Label1.TextSize = 14
DoEvents '<---<<< without this, it returns either "random" or previous values
Dim tmpSize As CameraSize = Fn.GetLBLTextInfo(Label1)
B4X:
'gets the text size of a label
'returns CameraSize (ENM) width and height type structure
Sub GetLBLTextInfo(lbl As Label) As CameraSize
Dim tmpSize As CameraSize
tmpSize.Initialize
Dim TMS2 As Reflector
lbl.Width = -2
lbl.Height = -2
TMS2.Target = lbl
tmpSize.Width = TMS2.RunMethod("getWidth")
tmpSize.Height = TMS2.RunMethod("getHeight")
Return tmpSize
End Sub