Old 14th January 2021, 23:04   #1
nashtor
Junior Member
 
Join Date: Feb 2013
Posts: 11
Question: Center Align DropList

Hello there,

I am trying to align the strings listed inside a droplist to the horizontal center of said droplist.
Having quite a hard time trying to do so.
${AddStyle} or ${AddExStyle} in combination with ${ES_CENTER} or ${SS_CENTER} does not seem to work for me.
Google brings up html, c#, etc. but nothing what would directly help me or maybe I am just blind.

Does anyone here know of a workaround, besides trying to add spaces to the strings to center them manually, which opens another can of problems for me ?

Thank you for your time!

PHP Code:
!include "MUI2.nsh"
!include "nsDialogs.nsh"

!define PRODUCTNAME "DropListAlignCenter"
Name "${PRODUCTNAME}"
OutFile "${PRODUCTNAME}.exe"

RequestExecutionLevel user

Var DropList

!insertmacro MUI_LANGUAGE "English"

Page custom nsDialogsMainPage


Section 
""
SectionEnd

Function nsDialogsMainPage
    
    nsDialogs
::Create 1044
    Pop 
$0

    
${If} $== error
        Abort
    
${EndIf}
    
    ${
NSD_CreateDropList100u 50u 120u 200u ""
    
Pop $DropList
    
    
${NSD_CB_AddString$DropList "Alice"
    
${NSD_CB_AddString$DropList "Franklin"
    
${NSD_CB_AddString$DropList "set"
    
${NSD_CB_AddString$DropList "v0.09"
    
${NSD_CB_AddString$DropList "Apple Computer, Inc."
    
${NSD_CB_AddString$DropList "Microsoft Corporation"
    
    
nsDialogs::Show
    
FunctionEnd 
nashtor is offline   Reply With Quote
Old 15th January 2021, 15:08   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,355
You can't just mix and match random styles. Combobox styles are CBS_* and there is no style for alignment. The only way to make a droplist center its text would be to use the CBS_OWNERDRAWFIXED style and custom draw. This can only be done with a custom plug-in.

You can also fake it with a ComboBox by playing with its edit control:
PHP Code:
Page Custom custpagecr
!include nsDialogs.nsh

Function custpagecr
nsDialogs
::Create 1018
Pop 
$0

${NSD_CreateComboBox0 13u 100% -13u ""
Pop $0
${NSD_CB_AppendString} $"Hello"
${NSD_CB_AppendString} $"World"
${NSD_CB_SetSelectionIndex} $0 0
FindWindow 
$"EDIT" "" $0
${NSD_AddStyle} $${ES_CENTER}|${ES_READONLY}
${
NSD_Edit_SetReadOnly} $1 1

nsDialogs
::Show
FunctionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 15th January 2021, 22:57   #3
nashtor
Junior Member
 
Join Date: Feb 2013
Posts: 11
Thanks a lot, especially for your example!
nashtor is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump