Reading the width of a control

  1. last year

    Art G

    18 May 2018 Prescott AZ

    In a view's Activate event, when I access a control's Width I always get 100. Have the constraints not kicked in yet?

  2. 8 months ago

    Derk J

    7 Mar 2019 Pre-Release Testers, Xojo Pro

    @Art G In a view's Activate event, when I access a control's Width I always get 100. Have the constraints not kicked in yet?

    Well i seem to have this issue too with 2018R4.. Anyone have an update how to get the TRUE width of a control ?

  3. Emile S

    7 Mar 2019 Europe (France, Strasbourg)
    Edited 8 months ago

    Not here:

    Sub Open() Handles Open
      L_Info.Text = "cLinux.Width: " + Str(cLinux.Width)
    End Sub

    Returns 128, 128 is the correct result in that case.

  4. Derk J

    7 Mar 2019 Pre-Release Testers, Xojo Pro

    @Emile S Not here:

    Sub Open() Handles Open
      L_Info.Text = "cLinux.Width: " + Str(cLinux.Width)
    End Sub

    Returns 128, 128 is the correct result in that case.

    Is it iOS where you get this?

  5. Emile S

    7 Mar 2019 Europe (France, Strasbourg)

    I just saw the channel name. Sorry, I get that on Desktop (El Capitan).

    “I’m so tired…“

  6. Jeremie L

    7 Mar 2019 Pre-Release Testers, Xojo Pro, XDC Speakers Europe (France) - getpackr.io

    Using iOSDesignExtensions you can use the GetBoundsXC function to get the real width of a control.

    Usually in the Activate event the layout is already settled and you shouldn't get 100 each time.
    In Open event, forget about getting the width.

    However on some complex layouts, you might be better calling a timer with 10ms delay :

    1. Add a function to your view

    Public Sub DelayedLayout()
     //Do something with control width
    End Sub

    2. In View.activate event:

    xojo.core.timer.calllater(10, AddressOf DelayedLayout)

    I use that very often in iOS apps

or Sign Up to reply!