Detect Control Resize?

interesting how many things I assumed are there but don’t seem to be…

I need to detect if a control (specifically a listbox) has changed size, either as a programatic change, or because its edges are locked to a window that changed size

I blindly assumed that all RectControls had RESIZED and RESIZING events :frowning:

[Note a timer won’t work, I need it all self contained in the control itself]

For some reason my list box thinks it has TWO columns, until I click on it, and I need it to redraw if it changes size

You can save the control size on Open, to a property. Then, on Paint (if a Canvas control) or CellBackgroundPaint get the current control size, and do whatever you want with it. You do that on Paint and CellbackgroundPaint because they get called after they are resized.

This turns out to work perfectly in CellBackGroundPaint Event

  //
  // Adjust Column Width
  //
  x=Self.column(0).WidthActual+2
  If (x<Self.width) Or (zRightJustified And x>Self.width) Then 
    Self.column(0).WidthActual=Self.width-2
  End If

Will work for canvas and listbox. Other controls, not so much.

yup, but for now all I needed it to do was work for a list box :slight_smile:

Placing a control locked on a ContainerControl is a way to have Resizing and Resize.

That’s … brilliant!

Yes that will make it resize… but the control itself has no event to tell it that it DID resize

The ContainerControl being intrinsically a window has Resized and Resizing. So if you place your control into one and lock it 4 sides making sure the CC has the same size, resizing the CC instance will trigger the appropriate event.

This could be like using a cannon to kill flies, but…

https://github.com/maxvalle/NotificationKit

CustomRectangle with properties

  • mHeight as Integer
  • mWidth as Integer
  • Timer1 as Timer

Event definitions :

  • Open
  • Resized

Sub CheckSize(sender as timer) if me.width <> mwidth or me.Height <> mHeight then mWidth = me.width mHeight = me.Height RaiseEvent Resized end if End Sub

[code]Sub Open()
RaiseEvent Open
mWidth = me.width
mHeight = me.height

Timer1 = New Timer
Timer1.Period = 1000
Timer1.Mode = Timer.ModeMultiple

AddHandler Timer1.Action, AddressOf CheckSize
End Sub
[/code]

Works for any control. I left a period of 1000 but something like 100 is probably better for an instant response.

[quote=176843:@Michel Bujardet]CustomRectangle with properties

  • mHeight as Integer
  • mWidth as Integer
  • Timer1 as Timer

Event definitions :

  • Open
  • Resized

Sub CheckSize(sender as timer) if me.width <> mwidth or me.Height <> mHeight then mWidth = me.width mHeight = me.Height RaiseEvent Resized end if End Sub

[code]Sub Open()
RaiseEvent Open
mWidth = me.width
mHeight = me.height

Timer1 = New Timer
Timer1.Period = 1000
Timer1.Mode = Timer.ModeMultiple

AddHandler Timer1.Action, AddressOf CheckSize
End Sub
[/code]

Works for any control. I left a period of 1000 but something like 100 is probably better for an instant response.[/quote]

Timer is really overkilling if you have many controls using it.
Why not simply overlay a canvas and use the Canvas.Paint event to detect a resize?

[quote=176846:@Massimo Valle]Timer is really overkilling if you have many controls using it.
Why not simply overlay a canvas and use the Canvas.Paint event to detect a resize?[/quote]

My point was to show there are many ways to detect resized. The timer is there to get a real time resized, but is certainly not mandatory. CheckSize could also be called on all the window.Control() when a Resized occurs on self.

Overlaying a canvas usually is no problem on Mac, but on Windows it can prevent some events to execute. Plus the risk of flickering.

[quote=176727:@Dave S]This turns out to work perfectly in CellBackGroundPaint Event

// // Adjust Column Width // x=Self.column(0).WidthActual+2 If (x<Self.width) Or (zRightJustified And x>Self.width) Then Self.column(0).WidthActual=Self.width-2 End If [/quote]

Suggestion: Limit this code to column 0, row 0. No need to run for every cell.

In actual use, it does exactly that