Floating positioning in Dialogs

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Floating positioning in Dialogs

Post by Jerry Thomas » Thu Dec 02, 2010 5:03 pm

Is there a way to have floating positioning in Dialogs?

What I want is for user to make a selection from a list box.

If selection = a
.Panel A visible = True
.Panel B visible = False
If selection = b
.Panel A visible = False . . (Collapsed so Panel B is directly under Listbox)
.Panel B visible = True

I know I could change 'Top' to move the panels, but I am hoping there is an easier way without having to keep up with the height of the different panels. (There will be 8-10 panels)

Code: Select all

Dialog>Test
object Test: TForm
  Left = 669
  Top = 186
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 608
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel A'
    TabOrder = 0
    object Label1: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label1'
    end
  end
  object MSListBox1: tMSListBox
    Left = 30
    Top = 8
    Width = 121
    Height = 97
    ItemHeight = 13
    TabOrder = 1
    SelectedIndex = -1
  end
  object Edit1: TEdit
    Left = 211
    Top = 42
    Width = 121
    Height = 21
    TabOrder = 2
    Text = 'Make Selection...'
  end
  object Panel2: TPanel
    Left = 34
    Top = 211
    Width = 185
    Height = 70
    Caption = 'Panel B'
    TabOrder = 3
    object Label2: TLabel
      Left = 16
      Top = 16
      Width = 32
      Height = 13
      Caption = 'Label2'
    end
  end
end
EndDialog>Test

AddDialogHandler>Test,MSListBox1,OnClick,DoClick

Let>items=a%CRLF%b%CRLF%both
SetDialogProperty>Test,MSListBox1,Text,items

Show>Test,r

SRT>DoClick
  GetDialogProperty>Test,MSListBox1,SelectedItems,SelectedItem
  SetDialogProperty>Test,Edit1,Text,SelectedItem
  If>SelectedItem=a
    SetDialogProperty>Test,Panel1,Height,70
    SetDialogProperty>Test,Panel1,Visible,True
    SetDialogProperty>Test,Panel2,Height,0
    SetDialogProperty>Test,Panel2,Visible,False
  Else
    If>SelectedItem=b
      SetDialogProperty>Test,Panel1,Height,0
      SetDialogProperty>Test,Panel1,Visible,False
      SetDialogProperty>Test,Panel2,Height,70
      SetDialogProperty>Test,Panel2,Visible,True
    Else
      SetDialogProperty>Test,Panel1,Height,70
      SetDialogProperty>Test,Panel1,Visible,True
      SetDialogProperty>Test,Panel2,Height,70
      SetDialogProperty>Test,Panel2,Visible,True
    Endif
  Endif
  
END>DoClick
[/code]
Thanks,
Jerry

[email protected]

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 02, 2010 5:25 pm

If I understand correctly, you want to be able to automatically arrange the selected visible panels without actually coding their positions. I can't say for certain but I suspect that is not going to happen. But, from the code samples you've submitted to the forum, I do think you have the skills needed to code your panel sizes into variables then write a single subroutine that will do your panel position management.

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Dec 02, 2010 7:49 pm

Here's an uncommented sample

Code: Select all

Let>Panel1_Wide=185
Let>Panel1_High=45
Let>Panel2_Wide=185
Let>Panel2_High=77
Let>Panel3_Wide=185
Let>Panel3_High=65
Let>Panel4_Wide=185
Let>Panel4_High=165
Let>Panel5_Wide=185
Let>Panel5_High=65
Let>Panel6_Wide=185
Let>Panel6_High=65
Let>Panel7_Wide=185
Let>Panel7_High=65
Let>Panel8_Wide=185
Let>Panel8_High=65
Let>Panel9_Wide=185
Let>Panel9_High=65
Let>Panel10_Wide=185
Let>Panel10_High=65
VBSTART
VBEND

Dialog>Test
object Test: TForm
  Left = 669
  Top = 186
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 608
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel A'
    TabOrder = 0
    object Label1: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label1'
    end
  end
    object Panel2: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel B'
    TabOrder = 0
    object Label2: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label2'
    end
  end
    object Panel3: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel C'
    TabOrder = 0
    object Label3: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label3'
    end
  end
    object Panel4: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel D'
    TabOrder = 0
    object Label4: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label4'
    end
  end
    object Panel5: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel E'
    TabOrder = 0
    object Label5: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label5'
    end
  end
    object Panel6: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel F'
    TabOrder = 0
    object Label6: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label6'
    end
  end
    object Panel7: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel G'
    TabOrder = 0
    object Label7: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label7'
    end
  end
    object Panel8: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel H'
    TabOrder = 0
    object Label8: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label8'
    end
  end
    object Panel9: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel I'
    TabOrder = 0
    object Label9: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label9'
    end
  end
    object Panel10: TPanel
    Left = 29
    Top = 128
    Width = 185
    Height = 65
    Caption = 'Panel J'
    TabOrder = 0
    object Label10: TLabel
      Left = 8
      Top = 8
      Width = 32
      Height = 13
      Caption = 'Label10'
    end
  end
  object MSListBox1: tMSListBox
    Left = 30
    Top = 8
    Width = 121
    Height = 97
    ItemHeight = 13
    TabOrder = 1
    SelectedIndex = -1
  end
  object Edit1: TEdit
    Left = 211
    Top = 42
    Width = 121
    Height = 21
    TabOrder = 2
    Text = 'Make Selection...'
  end
end
EndDialog>Test

GoSub>Initialize

SRT>Initialize
  Let>kk=0
  Repeat>kk
    Add>kk,1
    SetDialogProperty>Test,Panel%kk%,Visible,False
    Let>wide=Panel%kk%_wide
    Let>high=Panel%kk%_high
    SetDialogProperty>Test,Panel%kk%,Height,high
    SetDialogProperty>Test,Panel%kk%,Width,wide
  Until>kk=10
END>Initialize
GetDialogProperty>Test,Panel1,Left,Initial_Xpos
GetDialogProperty>Test,Panel1,Top,Initial_Ypos
Let>Xpos=Initial_Xpos
Let>Ypos=Initial_Ypos
AddDialogHandler>Test,MSListBox1,OnClick,DoClick

Let>items=a%CRLF%ab%CRLF%abc%CRLF%abcd%CRLF%abcde%CRLF%abcdef%CRLF%abcdefg%CRLF%abcdefgh%CRLF%abcdefghi%CRLF%abcdefghij%CRLF%
SetDialogProperty>Test,MSListBox1,Text,items

Show>Test,r

SRT>DoClick
  GoSub>Initialize
  GetDialogProperty>Test,MSListBox1,SelectedItems,SelectedItem
  RegEx>.,SelectedItem,0,item,item_count,0
  SetDialogProperty>Test,Edit1,Text,SelectedItem
  Let>kkk=0
  Repeat>kkk
    Add>kkk,1
    Let>value=item_%kkk%
    VbEval>(asc("%value%")-96),dec
    Let>panel=panel%dec%
    SetDialogProperty>Test,Panel,Visible,True
    SetDialogProperty>Test,Panel,Top,Ypos
    GetDialogProperty>Test,Panel,Height,Panel_Ht
    Let>Ypos={%Ypos%+5+%Panel_Ht%}
  Until>kkk=%item_count%
  Let>Xpos=Initial_Xpos
  Let>Ypos=Initial_Ypos
END>DoClick

Jerry Thomas
Macro Veteran
Posts: 267
Joined: Mon Sep 27, 2010 8:57 pm
Location: Seattle, WA

Post by Jerry Thomas » Thu Dec 02, 2010 9:07 pm

Actually it will be a little simpler because I don't have to worry about height and width.
All panels will the full width and I will GetProp Height while dialog is loading (height based on design rather than hardcoded).

I will just have to walk through the Panels and see if Visible=True or not and adjust Top of following panel accordingly.

Thanks for input!
Thanks,
Jerry

[email protected]

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts