Page 1 of 1

Resizing elements when parent dockable panel is resized

Posted: Fri Apr 05, 2013 9:47 am
by m42i
I've got a persistent dockable panel with some elements inside. When I resize the panel those elements won't resize with them.

Here is my sample code. When I resize the PanelX, the ActiveX control inside won't resize with it.

https://dl.dropbox.com/u/344000/Demo.mmip

Code: Select all

' Demo file for resizing a persistent dockable panel
Const BTN_MARGIN = 5 ' Defines the standard margin between buttons
Const BTN_HEIGHT = 25 ' Defines standard height of a button
Const BTN_WIDTH = 80 ' Defines standard width of a button
Const TIME_WIDTH = 50 ' Defines standard width of a time label

Dim PanelX

Sub OnStartUp
    Call CreateMainPanel
End Sub

Sub DoClick
    SDB.MessageBox "Hello!", mtInformation, Array(mbOk)
End Sub

Sub CreateMainPanel
    Set UI = SDB.UI
    Set PanelX = UI.NewDockablePersistentPanel("PanelX")
    If PanelX.IsNew Then
        PanelX.DockedTo = 4 
    End If
    PanelX.ShowCaption = True
    PanelX.Common.Visible = True

    Set ButtonA = UI.NewButton(PanelX)
    Set SDB.Objects("ButtonA") = ButtonA
    ButtonA.Common.Visible = True
    ButtonA.Common.ControlName = "ButtonA"
    ButtonA.Caption = SDB.Localize("Play")
    ButtonA.Common.SetRect BTN_MARGIN, BTN_MARGIN, BTN_WIDTH, BTN_HEIGHT
    Script.RegisterEvent ButtonA, "OnClick", "DoClick"

    Set WebPanel = UI.NewActiveX(PanelX, "Shell.Explorer")
    Set SDB.Objects("WebPanel") = WebPanel
    WebPanel.Common.Visible = True
    WebPanel.Common.ControlName = "WebPanel"
    WebPanel.Common.Align = 0
    WebPanel.Interf.Navigate "about:" ' A trick to make sure document exists, from Wiki
    WebPanel.Common.SetClientRect BTN_MARGIN, 2*BTN_MARGIN + BTN_HEIGHT, _
        PanelX.Common.Width - 3*BTN_MARGIN, _
        PanelX.Common.Height - 4*BTN_MARGIN - 2*BTN_HEIGHT
End Sub

Sub Uninstall
    PanelX.Common.Visible = False
    Set PanelX = Nothing
    Set SDB.Objects("PanelX") = Nothing
    Script.UnRegisterEvents SDB
End Sub

Re: Resizing elements when parent dockable panel is resized

Posted: Fri Apr 05, 2013 10:11 am
by m42i
One possibility that occurred to me is, to make a new RedrawTimer, that will refresh the size of all elements every second or so. But I'd hope for a more elegant way to do this.

Re: Resizing elements when parent dockable panel is resized

Posted: Sat Apr 06, 2013 6:13 am
by trixmoto
Take a look at my BatchArtFinder script, this has a similar layout. The ActiveX is set to align 5 and there's then a panel which is set to align 2 (although that's bottom and I think you want top) and then any buttons go on the panel.

Re: Resizing elements when parent dockable panel is resized

Posted: Sat Apr 06, 2013 1:20 pm
by m42i
Ok, I found my mistake. I thought the names in parenthesis in the wiki were constants. After defining them, it works fine. :)