Jump to content
Sign in to follow this  
sugi

Dynamic size of label/checkbox control

Recommended Posts

sugi

Hello,

I need to figure out how to calculate the width that a checkbox needs to have to show the full text. At the same time, wasting space by oversizing them is not an option, because I have to place an input field right next to it.

Basically the GUI I have to create looks like the following (with a non-fixed-width font):

[ ] Point 1 _____________________

[ ] Point 1.1 ___________________

[ ] Point 1.2 ___________________

[ ] Point 2 _____________________

Where the underscores stand for the input box. If I know how big the checkboxes are, I can size the input box automatically.

How can I calculate how I have to size the checkboxes?

Thanks!

Edited by sugi

Share this post


Link to post
Share on other sites
Polyphem

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $msg

GUICreate("My GUI",200,200)  ; will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW)       ; will display an empty dialog box

$string_checkbox1 = "Teststring a"
$string_checkbox2 = "Teststring bbbbbbb"
$string_checkbox3 = "Teststring c"

GUICtrlCreateLabel("",0,0,200,200)
GUICtrlSetBkColor(-1, 0x0000ff)     ; Green

$checkbox1 = GUICtrlCreateCheckbox($string_checkbox1,10,20,stringlen($string_checkbox1)*6.5,20)
$checkbox2 = GUICtrlCreateCheckbox($string_checkbox2,10,40,stringlen($string_checkbox2)*6.5,20)
$checkbox3 = GUICtrlCreateCheckbox($string_checkbox3,10,60,stringlen($string_checkbox3)*6.5,20)

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()


This post will be edited again by Polyphem: Tomorrow, 11:55 AM

Share this post


Link to post
Share on other sites
Polyphem

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Local $msg

GUICreate("My GUI",200,200)  ; will create a dialog box that when displayed is centered
GUISetState(@SW_SHOW)       ; will display an empty dialog box

$string_checkbox1 = "Teststring a"
$string_checkbox2 = "Teststring bbbbbbb"
$string_checkbox3 = "Teststring c"

GUICtrlCreateLabel("",0,0,200,200)
GUICtrlSetBkColor(-1, 0x0000ff)     ; Blue
GUICtrlSetState(-1, $GUI_DISABLE)

$checkbox1 = GUICtrlCreateCheckbox($string_checkbox1,10,20,stringlen($string_checkbox1)*6.5,20)
$checkbox2 = GUICtrlCreateCheckbox($string_checkbox2,10,40,stringlen($string_checkbox2)*6.5,20)
$checkbox3 = GUICtrlCreateCheckbox($string_checkbox3,10,60,stringlen($string_checkbox3)*6.5,20)

GUICtrlCreateInput("",10+stringlen($string_checkbox1)*6.5,20,180-stringlen($string_checkbox1)*6.5,20)
GUICtrlCreateInput("",10+stringlen($string_checkbox2)*6.5,40,180-stringlen($string_checkbox2)*6.5,20)
GUICtrlCreateInput("",10+stringlen($string_checkbox3)*6.5,60,180-stringlen($string_checkbox3)*6.5,20)


; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()

Edit: Blue, not Green ;)...

Edited by Polyphem

This post will be edited again by Polyphem: Tomorrow, 11:55 AM

Share this post


Link to post
Share on other sites
sugi

Thank you smashly, that seems to be exactly what I was looking for!

$string_checkbox1 = "Teststring a"
$string_checkbox2 = "Teststring bbbbbbb"
$string_checkbox3 = "Teststring c"
$checkbox1 = GUICtrlCreateCheckbox($string_checkbox1,10,20,stringlen($string_checkbox1)*6.5,20)
$checkbox2 = GUICtrlCreateCheckbox($string_checkbox2,10,40,stringlen($string_checkbox2)*6.5,20)
$checkbox3 = GUICtrlCreateCheckbox($string_checkbox3,10,60,stringlen($string_checkbox3)*6.5,20)
GUICtrlCreateInput("",10+stringlen($string_checkbox1)*6.5,20,180-stringlen($string_checkbox1)*6.5,20)
GUICtrlCreateInput("",10+stringlen($string_checkbox2)*6.5,40,180-stringlen($string_checkbox2)*6.5,20)
GUICtrlCreateInput("",10+stringlen($string_checkbox3)*6.5,60,180-stringlen($string_checkbox3)*6.5,20)oÝ÷ Ûú®¢×©ä°ú%Ê^»­¶½êÚì"vØh}§!j¸¬^ «y:ò¶¬zËkx,jëh×6$string_checkbox1 = "Teststring IIIIIII"
$string_checkbox2 = "Teststring WWWWWWW"

Edit: looks like the quick edit function does have a problem with me

Edited by sugi

Share this post


Link to post
Share on other sites
Polyphem

Oh, noch ein Hamburger ;) , na, einen Versuch wars wert :D (was worth a try)...


This post will be edited again by Polyphem: Tomorrow, 11:55 AM

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×