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

In reply to Re: adding multiple labels with win32::GUI by rcseege
in thread adding multiple labels with win32::GUI by paulehr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.