Code Comments
Programming Forum and web based access to our favorite programming groups.I am just learning Win32::GUI. I created a simple window with a
checkbox, a label, and a textfield. Initially, the label and textfield
are disabled. What should happen is they should become enabled if you
click the checkbox. I cannot figure out how to do this. As you can see
from the code below, I tried creating a Click event to set the
variable so that the label and textfield would be enabled, but
apparently, I have to redraw or refresh the window somehow. Can anyone
please help?
--------------Code follows-----------------------
use Win32::GUI;
$Display=1;
$main = Win32::GUI::DialogBox->new(
-name => 'Main',
-width => 250,
-height => 100,
);
$main->AddCheckbox(
-name => 'CheckBox1',
-width => 225,
-left => 10,
-top => 10,
-tabstop => 1,
-disabled => 0,
-visible => 1,
-text => 'Check this box to enable the next section');
$main->AddLabel(
-name => 'label1',
-left => 30,
-top => 30,
-disabled => "$Display",
-text => "Type something here");
$main->AddTextfield(
-name => 'textbox1',
-width => 175,
-height => 20,
-left => 28,
-top => 45,
-tabstop => 1,
-disabled => "$Display",
-visible => 1);
$main->Show();
Win32::GUI::Dialog();
sub CheckBox1_Click {
if($Display==1){
$Display=0}
else{$Display=1}
}
sub Main_Terminate {
-1;
}
Post Follow-up to this messageredneck13@hotmail.com (omoore) wrote in message news:<ac62fb69.0408111148.25bea683@posting.
google.com>...
> I am just learning Win32::GUI. I created a simple window with a
> checkbox, a label, and a textfield. Initially, the label and textfield
> are disabled. What should happen is they should become enabled if you
> click the checkbox. I cannot figure out how to do this. As you can see
> from the code below, I tried creating a Click event to set the
> variable so that the label and textfield would be enabled, but
> apparently, I have to redraw or refresh the window somehow. Can anyone
> please help?
Nevermind, I figured it out. For those of you that may be curious,
the secret lies in assigning each of the objects to its own variable.
You can then apply the Enable and Disable methods to those variables.
This also negates the need for my original $Display variable.
Following is the code that did the trick.
use Win32::GUI;
$main = Win32::GUI::DialogBox->new(
-name => 'Main',
-width => 250,
-height => 100,
);
$checkbox1=$main->AddCheckbox(
-name => 'CheckBox1',
-width => 225,
-left => 10,
-top => 10,
-tabstop => 1,
-disabled => 0,
-visible => 1,
-text => 'Check this box to enable the next section');
$label1=$main->AddLabel(
-name => 'label1',
-left => 30,
-top => 30,
-disabled => 1,
-text => "Type something here");
$textbox1=$main->AddTextfield(
-name => 'textbox1',
-width => 175,
-height => 20,
-left => 28,
-top => 45,
-tabstop => 1,
-disabled => 1,
-visible => 1);
$main->Show();
Win32::GUI::Dialog();
sub CheckBox1_Click {
if($checkbox1->Checked()==1){
$label1->Enable();
$textbox1->Enable();
}
else{
$label1->Disable();
$textbox1->Disable();
}
}
sub Main_Terminate {
-1;
}
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.