Below is a complete program that shows
how to allow the user to change colors in a
textfield on the fly.   enjoy!


# Eric Hansen, ITSi, Dallas, TX July 1999
use Win32::GUI;
use Time::localtime;

# Hide the Dos Window 
($DOShwnd, $DOShinstance) = GUI::GetPerlWindow();
GUI::Hide($DOShwnd);

$mm=localtime->mon()+1;
$dd=localtime->mday();
@fields = split(/ /,ctime());
$lastfld=$#fields;
$yyyy=$fields[$lastfld];
$Today=sprintf("%4s%02s%02s",$yyyy,$mm,$dd);

$W = new GUI::DialogBox (
    -title    => "Change Color On The Fly",
    -left     => 100, 
    -top      => 20, 
    -width    => 250, 
    -height   => 250,
    -name     => "Window",
);
 
$Font = new Win32::GUI::Font(
    -name => "Courier New",
    -size => 12,
    -weight => 700,
    -height => -14,
);

$BeginDateButton = $W->AddButton(-name => "BeginDateButton",
                      -text  => "Color", 
                      -left => 145, 
                      -top => 100,
                      -group => 1,
                      -tabstop => 1,
                      -height => 25, 
                      -width => 30 );

$BeginDate = $W->AddTextfield(-name => "BeginDate",
                      -text  => $Today, 
                      -font => $Font,
                      -foreground => 0x8080FF,    # soft red
                      -left => 65, 
                      -top => 100, 
                      -group => 1,
                      -tabstop => 1, 
                      -height => 20,
                      -width => 75 );
$BeginDate->SetFocus();
$BeginDate->Select(0,length($BeginDate->Text()));
$BeginDate->SendMessage(197, 8, 0);  # limit to 8 characters input

$W->Show; 
GUI::Dialog();

sub BeginDateButton_Click {
   my $text = $BeginDate->Text();
   my $color = GUI::ChooseColor(-owner => $W);
   if ($color) {
        $BeginDate->Change(-foreground => $color, -text => $text);
   }
}

Window_Terminate {
    GUI::Show($DOShwnd);
    return -1;
}

# End Script

Regards,
Eric Hansen


Reply via email to