Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Win32:GUI Label resize

by hennesse (Beadle)
on Oct 29, 2011 at 01:56 UTC ( [id://934544]=perlquestion: print w/replies, xml ) Need Help??

hennesse has asked for the wisdom of the Perl Monks concerning the following question:

How do you get Win32:GUI() to resize your label?

When you do:

my $label = $main->AddLabel( -text =>"Something", );
Win32:GUI automatically determines the size of the label.

But when you do:

Win32::GUI::Change($label->{-handle}, ( -text => "Longer label here", );
it keeps the same size, and some of the text doesn't show.

How do you make it recalculate?

Thanks - Dave

Replies are listed 'Best First'.
Re: Win32:GUI Label resize
by BrowserUk (Patriarch) on Oct 29, 2011 at 04:24 UTC

    Windows native label controls do not automatically resize when the text changes, which means that unless Win32::GUI add that functionality -- which I doubt given its minimalist approach to things -- that you would need to do that yourself.

    That would mean setting up a _Change() handler for the label control and handling the text change yourself. That would then involve using FontMetrics to calculate the size of the text given the current Font, and then calling Resize() on the label accordingly.

    Probably your easiest bet would be to just Remove() the existing Label control and then AddLabel() with the new text.

    An alternative would be to pre-size the Label (-Width -Height) to a reasonable maximum size. Then when the text changes the size of the Label doesn't need to. It also avoids the possibility of knock-on effects; like having to resize the main window, or move other controls around to accommodate the resized Label.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      BrowserUK,

      I suspected that was the case. I tried redraw, but that didn't do anything. I couldn't find Remove(), but pre-sizing the label will do just fine for my simple application.

      Thank you!

        I couldn't find Remove()

        Removal of controls is another action subject to Win32::GUIs minimalism, but isn't too hard to do. See Re: remove elements win32 gui.

        but pre-sizing the label will do just fine for my simple application.

        It is by far the simplest. Also, I find windows and dialogs that re-structure themselves when resized very annoying.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Win32:GUI Label resize
by Anonymous Monk on Oct 29, 2011 at 02:27 UTC

    How do you make it recalculate?

    Search the manual for repack, refresh, reload, redraw, validate, invalidate, layout, forcelayout, update

    One or more of those keywords will do it, they're pretty much universal among GUI toolkits

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://934544]
Approved by BrowserUk
Front-paged by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-04-23 14:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found