CheckBox Centered and Multiline text
Posted: Thu Feb 02, 2017 10:09 am
Grigory Filatov has adopted MULTILINE in CheckBox as more one property in 17.01 version. ![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
![Very Happy :D](./images/smilies/icon_e_biggrin.gif)
Exclusive forum for HMG, a Free / Open Source xBase WIN32/64 Bits / GUI Development System
https://www.hmgforum.com/
Code: Select all
function ChangeHeightOfCHeckBox
param cControl, cForm
local cText
local nLines
local nHandle
local nHeight
nHandle := GetControlHandle(cControl, cForm)
cText := GetWindowText(nHandle)
nLines := HB_TokenCount(cText, .T. /*lEOL*/)
nHeight := GetTextHeight(0, cText, GetWindowFont(nHandle)) * nLines
IF nLines > 1
HMG_ChangeWindowStyle(nHandle, 0x2000 /*BS_MULTILINE*/, NIL, .F.)
SetProperty(cForm, cControl, "Height", nHeight)
ENDIF
return nHeight
Code: Select all
#include <hmg.ch>
Function Main()
DEFINE WINDOW Demo1 AT 163, 357 WIDTH 188 HEIGHT 251 TITLE "CheckBox Text Height" MAIN NOMAXIMIZE NOMINIMIZE NOSIZE
DEFINE CHECKBOX Check_1
ROW 30
COL 40
WIDTH 100
HEIGHT 28
CAPTION "Check_1 "+CRLF+"in three"+CRLF+"lines" // Forcing 3 line breaks
BACKCOLOR {192,192,192}
END CHECKBOX
DEFINE CHECKBOX Check_2
ROW 100
COL 40
WIDTH 100
HEIGHT 60
CAPTION "Check_2 with long text that it could takes more than three lines long"
BACKCOLOR {192,192,192}
END CHECKBOX
END WINDOW
Demo1.Center
CheckBoxAutoAdjust("Check_1", "Demo1", .T.)
CheckBoxAutoAdjust("Check_2", "Demo1")
Demo1.Activate
Return Nil
Function CheckBoxAutoAdjust(cControl, cForm, lCenter)
LOCAL nHandle := GetControlHandle(cControl, cForm)
LOCAL nWidth := GetProperty(cForm, cControl,"WIDTH")
LOCAL cText := GetProperty(cForm, cControl,"CAPTION")
LOCAL nLines, nTextWidth, nTextHeight, Style, nBoxSize := 20
DEFAULT lCenter := .F.
nTextWidth := GetTextWidth(0, cText, GetWindowFont(nHandle))
Style := 0x2000 + If( lCenter, 0x300, 0x0 ) + 0xC00 // BS_MULTILINE + BS_CENTER + BS_VCENTER
If CRLF $ cText
nLines := hb_TokenCount(cText, .T. /*lEOL*/) + 1
Else
nLines := ( nTextWidth / ( nWidth - nBoxSize ) )
nLines := Int(nLines) + If(nLines == Int(nLines), 1, 2)
Endif
nTextHeight := GetTextHeight(0, cText, GetWindowFont(nHandle)) * nLines
HMG_ChangeWindowStyle(nHandle, Style, NIL, .F.)
SetProperty(cForm, cControl, "Height", nTextHeight)
Return Nil
Many thanks Marek.