Dialog padding/margin for labels

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Dialog padding/margin for labels

Post by Grovkillen » Mon Apr 24, 2023 11:53 am

I'm trying to use the background color of a label to indicate some status. But if you try this code and you will see that the background is a little too close to the beginning and end of the string and I would like to have a small padding to make it look better. I hope to get some guidance on how to add margin to the label.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'CustomDialog'
  ClientHeight = 211
  ClientWidth = 476
  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 Label1: TLabel
    Left = 16
    Top = 16
    Width = 119
    Height = 46
    Caption = 'Label1'
    Color = 8421631
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -40
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentColor = False
    ParentFont = False
    Transparent = False
  end
  object Label2: TLabel
    Left = 16
    Top = 86
    Width = 119
    Height = 46
    Caption = ' Label2 '
    Color = 8421631
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -40
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    ParentColor = False
    ParentFont = False
    Transparent = False
  end
end
EndDialog>Dialog1

Show>Dialog1,r
It's not ideal to add spaces before and after the string. I want to programmatically add the distance.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Dialog padding/margin for labels

Post by Dorian (MJT support) » Mon Apr 24, 2023 1:04 pm

I'd have though this would do it, but I can't get it to take effect :

Code: Select all

    Margins.Left = 25
    Margins.Top = 25
    Margins.Right = 25
    Margins.Bottom = 25
The only way I'm able to do it is forcing the label to be slightly wider.

Code: Select all

GetDialogProperty>Dialog1,Label1,Width,L1w
Let>L1w2=L1w+25
SetDialogProperty>Dialog1,Label1,Width,L1w2
OR

Code: Select all

GetDialogProperty>Dialog1,Label1,Width,L1w
SetDialogProperty>Dialog1,Label1,Width,{(%L1w%+25)}
I'll ask Marcus for some insight.
Yes, we have a Custom Scripting Service. Message me or go here

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Dialog padding/margin for labels

Post by hagchr » Tue Apr 25, 2023 2:49 am

For the last one you want to change to center alignment to get the padding uniform beginning/end.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Dialog padding/margin for labels

Post by Dorian (MJT support) » Tue Apr 25, 2023 7:09 am

Thank you for adding that. I forgot to mention that part.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Dialog padding/margin for labels

Post by Grovkillen » Tue Apr 25, 2023 9:37 am

Alignment isn't the same as background color. See this attached image of my dialog. The text "Släppt" is part of a bigger label which is the full width of the panel, the text "Status:" is also a label with the same size and placement as the former. The only difference is the alignment. So the suggested change isn't desirable.

Image

Code: Select all

Let>APP_VERSION=1.04.00
Let>APP_TITLE=Snooopy!
Let>APP_EXE=snooopy!
Let>DEFAULT_COLOR_BACKGROUND=1225395
Let>DEFAULT_COLOR_PANEL=10411999
Let>WARNING_COLOR=6447055
Let>SUCCESS_COLOR=10092288
Let>INFO_COLOR=3783666

Dialog>DialogSnooopy
object DialogSnooopy: TForm
  Left = 2167
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsNone
  Caption = 'CustomDialog'
  ClientHeight = 150
  ClientWidth = 150
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object APPINFO: TLabel
    Left = 5
    Top = 4
    Width = 3
    Height = 13
  end
  object MINIMIZE_MAXIMIZE: TLabel
    Left = 142
    Top = 4
    Width = 3
    Height = 13
    Alignment = taRightJustify
  end
  object PANEL: TPanel
    Left = 2
    Top = 20
    Width = 146
    Height = 128
    BevelOuter = bvNone
    Color = clLime
    ParentBackground = False
    TabOrder = 0
    object ACTIVE_FILE_NAME_label: TLabel
      Left = 2
      Top = 2
      Width = 39
      Height = 13
      Caption = 'Filnamn:'
    end
    object ACTIVE_FILE_NAME_data: TLabel
      Left = 89
      Top = 2
      Width = 55
      Height = 13
      Alignment = taRightJustify
      Caption = '1235444.stl'
    end
    object ACTIVE_FILE_TITLE_label: TLabel
      Left = 2
      Top = 17
      Width = 39
      Height = 13
      Caption = 'Benämning:'
    end
    object ACTIVE_FILE_TITLE_data: TLabel
      Left = 89
      Top = 17
      Width = 55
      Height = 13
      Alignment = taRightJustify
      Caption = 'Plåt'
    end
    object ACTIVE_FILE_REVISION_label: TLabel
      Left = 2
      Top = 32
      Width = 44
      Height = 13
      Caption = 'Revision:'
    end
    object ACTIVE_FILE_REVISION_data: TLabel
      Left = 102
      Top = 32
      Width = 42
      Height = 13
      Alignment = taRightJustify
      Caption = '1.01.001'
    end
    object ACTIVE_FILE_KM_label: TLabel
      Left = 2
      Top = 47
      Width = 33
      Height = 13
      Caption = 'Senaste KM:'
    end
    object ACTIVE_FILE_KM_data: TLabel
      Left = 114
      Top = 47
      Width = 30
      Height = 13
      Alignment = taRightJustify
      Caption = '230231'
    end
    object ACTIVE_FILE_STATUS_label: TLabel
      Left = 2
      Top = 62
      Width = 33
      Height = 13
      Caption = 'Status:'
    end
    object ACTIVE_FILE_STATUS_data: TLabel
      Left = 114
      Top = 62
      Width = 30
      Height = 13
      Alignment = taRightJustify
      Caption = 'Sl'#228'ppt'
      Color = clRed
      Transparent = False
      Font.Color = clWhite
    end
    object ACTIVE_FILE_OWNER_label: TLabel
      Left = 2
      Top = 77
      Width = 33
      Height = 13
      Caption = 'Ägarskap:'
    end
    object ACTIVE_FILE_OWNER_data: TLabel
      Left = 114
      Top = 77
      Width = 30
      Height = 13
      Alignment = taRightJustify
      Caption = 'Jimmy Westberg'
    end
  end
end
EndDialog>DialogSnooopy

SetDialogProperty>DialogSnooopy,,Color,%DEFAULT_COLOR_BACKGROUND%
SetDialogProperty>DialogSnooopy,PANEL,Color,%DEFAULT_COLOR_PANEL%
SetDialogProperty>DialogSnooopy,APPINFO,Caption,%APP_TITLE% [%APP_VERSION%]
SetDialogProperty>DialogSnooopy,MINIMIZE_MAXIMIZE,Caption,+

Show>DialogSnooopy,r
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Dialog padding/margin for labels

Post by Grovkillen » Tue Apr 25, 2023 9:51 am

I see that my code got messed up by the Dialog Designer which changes width based on input text.... I'll do the padding using spaces even though I'd like to have it done by design. Please enlighten me if the padding/margin syntax is available. But consider this a non issue if it's not possible using MS.
Let>ME=%Script%

Running: 15.0.27
version history

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1386
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: Dialog padding/margin for labels

Post by Dorian (MJT support) » Tue Apr 25, 2023 9:54 am

Understood. I'll do my best to find out.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
Grovkillen
Automation Wizard
Posts: 1131
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Dialog padding/margin for labels

Post by Grovkillen » Tue Apr 25, 2023 9:54 am

Just for clarity. This is the code I use for my dialog:

Code: Select all

Let>APP_VERSION=1.04.00
Let>APP_TITLE=Snooopy!
Let>APP_EXE=snooopy!
Let>DEFAULT_COLOR_BACKGROUND=1225395
Let>DEFAULT_COLOR_PANEL=10411999
Let>WARNING_COLOR=6447055
Let>SUCCESS_COLOR=10092288
Let>INFO_COLOR=3783666

Dialog>DialogSnooopy
object DialogSnooopy: TForm
  Left = 2167
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsNone
  Caption = 'CustomDialog'
  ClientHeight = 150
  ClientWidth = 150
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  FormStyle = fsStayOnTop
  OldCreateOrder = True
  Position = poScreenCenter
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object APPINFO: TLabel
    Left = 5
    Top = 4
    Width = 3
    Height = 13
  end
  object MINIMIZE_MAXIMIZE: TLabel
    Left = 5
    Top = 4
    Width = 140
    Height = 13
    Alignment = taRightJustify
  end
  object PANEL: TPanel
    Left = 2
    Top = 20
    Width = 146
    Height = 128
    BevelOuter = bvNone
    Color = clLime
    ParentBackground = False
    TabOrder = 0
    object ACTIVE_FILE_NAME_label: TLabel
      Left = 2
      Top = 2
      Width = 142
      Height = 13
      Caption = 'Filnamn:'
    end
    object ACTIVE_FILE_NAME_data: TLabel
      Left = 2
      Top = 2
      Width = 142
      Height = 13
      Alignment = taRightJustify
      Caption = '1235444.stl'
    end
    object ACTIVE_FILE_TITLE_label: TLabel
      Left = 2
      Top = 17
      Width = 142
      Height = 13
      Caption = 'Benämning:'
    end
    object ACTIVE_FILE_TITLE_data: TLabel
      Left = 2
      Top = 17
      Width = 142
      Height = 13
      Alignment = taRightJustify
      Caption = 'Plåt'
    end
    object ACTIVE_FILE_REVISION_label: TLabel
      Left = 2
      Top = 32
      Width = 142
      Height = 13
      Caption = 'Revision:'
    end
    object ACTIVE_FILE_REVISION_data: TLabel
      Left = 2
      Top = 32
      Width = 142
      Height = 13
      Alignment = taRightJustify
      Caption = '1.01.001'
    end
    object ACTIVE_FILE_KM_label: TLabel
      Left = 2
      Top = 47
      Width = 142
      Height = 13
      Caption = 'Senaste KM:'
    end
    object ACTIVE_FILE_KM_data: TLabel
      Left = 2
      Top = 47
      Width = 142
      Height = 13
      Alignment = taRightJustify
      Caption = '230231'
    end
    object ACTIVE_FILE_STATUS_label: TLabel
      Left = 2
      Top = 62
      Width = 142
      Height = 13
      Caption = 'Status:'
    end
    object ACTIVE_FILE_STATUS_data: TLabel
      Left = 2
      Top = 62
      Width = 142
      Height = 13
      Alignment = taRightJustify
      Caption = 'Sl'#228'ppt'
      Transparent = False
      Font.Color = clWhite
    end
    object ACTIVE_FILE_OWNER_label: TLabel
      Left = 2
      Top = 77
      Width = 142
      Height = 13
      Caption = 'Ägarskap:'
    end
    object ACTIVE_FILE_OWNER_data: TLabel
      Left = 2
      Top = 77
      Width = 142
      Height = 13
      Alignment = taRightJustify
      Caption = 'Jimmy Westberg'
    end
  end
end
EndDialog>DialogSnooopy

SetDialogProperty>DialogSnooopy,,Color,%DEFAULT_COLOR_BACKGROUND%
SetDialogProperty>DialogSnooopy,PANEL,Color,%DEFAULT_COLOR_PANEL%
SetDialogProperty>DialogSnooopy,APPINFO,Caption,%APP_TITLE% [%APP_VERSION%]
SetDialogProperty>DialogSnooopy,ACTIVE_FILE_STATUS_data,Color,%WARNING_COLOR%
SetDialogProperty>DialogSnooopy,MINIMIZE_MAXIMIZE,Caption,+

Show>DialogSnooopy,r
Let>ME=%Script%

Running: 15.0.27
version history

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