Page 2 of 2

CheckBox Centered and Multiline text

Posted: Thu Feb 02, 2017 10:09 am
by Pablo César
Grigory Filatov has adopted MULTILINE in CheckBox as more one property in 17.01 version. :D

CheckBox can be MULTILINE

Posted: Tue Feb 07, 2017 7:14 am
by mol
I was wonder if this solution can be adapted to CHECKBOX control.
I've modified Krzysztof sample, and it's work very fine. Thanks for sharing your knowledge!
My change

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

CheckBox can be MULTILINE

Posted: Tue Feb 07, 2017 10:58 am
by Pablo César
Hi Marek,

Thanks for your interest and contribution. :)

I am very happy to know that we contribute and serve as inspiration for the noble colleagues here in the forum. :D

I made some adaptations based on your example that I found convenient and I share here with all of you:
 
Screen87.png
Screen87.png (8.55 KiB) Viewed 3545 times
 
Guy, joining all our esforces we get the best result and we win all together ! :P

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
Indeed to say we always learn a lot with colleagues like Krzysztof, Claudio and many all of us always when we are sharing... to all of them many thanks for participating at our community.
Image

But please Mr. Marek do not get me wrong, but it would have been more convenient for you to have posted your example in the CheckBox - Multiline post.

Here in this post we are dealing with RadioGroup issues.
Would you kindly ask to forum administrator to move these two messages (yours and mine about CheckBox) ?
So with this we do not mix the main subjects.

Can you please ask to Mr. Rathinagiri ?

Thanks in advanced.

Notes: Source code was re-edited to include style option.

Re: RadioGroup can be MULTILINE

Posted: Tue Feb 07, 2017 12:47 pm
by mol
No problem. My sample was a little digression to current topic.I don't want to assign CheckBox modification function to my account, because it's only Krzysztof solution little modification

CheckBox can be MULTILINE

Posted: Tue Feb 07, 2017 1:09 pm
by Pablo César
mol wrote: Tue Feb 07, 2017 12:47 pm No problem. My sample was a little digression to current topic.I don't want to assign CheckBox modification function to my account, because it's only Krzysztof solution little modification
Many thanks Marek. :)

If you had not posted your previous message, I would never imagine that in my first code was needed for improving...

Firstly when I make changes first I'm doing for myself and if I think it's good one then I share.
Far from wanting to compete with anyone here in the forum.
Someone knows more of something than someone, I know less than maybe someone and others know more than others in some things.
And when someone presents something better, I and the others should find this very healthy by improving something and instigating to do better...

No one is perfect and letting go of vanity aside is too good to give way for learning.

This is a highly altruistic place and if we do not make good use of it: why publish ? I am right ?

You don't worry and take in mind: we are rich and happy when we have options... :P

Re: RadioGroup can be MULTILINE

Posted: Tue Feb 07, 2017 4:01 pm
by mol
+1

CheckBox Centered and Multiline text

Posted: Tue Feb 07, 2017 10:02 pm
by Pablo César
Thank you Rathi for moving messages into here.