Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: adding multiple labels with win32::GUI

by rcseege (Pilgrim)
on Sep 09, 2006 at 20:56 UTC ( [id://572183]=note: print w/replies, xml ) Need Help??


in reply to adding multiple labels with win32::GUI

Update: For more information on dealing with Label positioning read below. After rereading your post, it sounds like you might be better off using a TextField, ListView, or Listbox control as BrowserUk suggested.

First, it should be Show instead of show, and second, you can drop it from the Label controls -- it's unnecessary.

This leaves you with the following:

use strict; use Win32::GUI; my $mw = Win32::GUI::Window->new ( -name => 'Main', -width => 300, -height => 100, -text => 'bbtrack', ); my $label1 = $mw->AddLabel( -text => "hello"); my $label2 = $mw->AddLabel( -text => "hello2"); $mw->Show(); Win32::GUI::Dialog();

What is going on is you are laying one Label directly on top of the other one so it looks as though only one is created. To verify this, change the text of the first Label to "hello world". Now, the overlay should be easy to see.

Try specifying the position of the second Label by using one or more of the following options: -left, -top, or -pos. Here are a few examples:

my $label2 = $mw->AddLabel( -text => "hello2", -left => 30);

or even:

my $label2 = $mw->AddLabel( -text => "hello2", -top => 15);

Of course, this can be problematic because of fonts so you could use the Height and Width methods:

my $label2 = $mw->AddLabel( -text => "hello2", -left => ($label1->Width + 2)); ## OR my $label2 = $mw->AddLabel( -text => "hello2", -top => ($label1->Height + 2));

You might also take a look at the GridLayout control. Here's one example:

use Win32::GUI; use Win32::GUI::GridLayout; my $mw = Win32::GUI::Window->new ( -name => 'Main', -width => 300, -height => 100, -text => 'bbtrack', ); my $grid = apply Win32::GUI::GridLayout($mw, 4, 4, 0, 0); for my $col (1 .. 4) { for my $row (1 .. 4) { my $lab = $mw->AddLabel( -name => "MainLabel$col$row", -text => "C: $col, R: $row"); $grid->add($lab, $col, $row); } } $grid->recalc; $mw->Show(); Win32::GUI::Dialog(); sub Main_Resize { $grid->recalc(); }
Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://572183]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (4)
As of 2024-04-19 06:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found