Johan Lindstrom wrote:
At 16:54 2005-11-17, Glenn W Munroe wrote:
The main window of my current project comprises a Grid control and a
TreeView, in a Windows Explorer-like layout. I would like to provide
the option of being able to resize the two controls by
click-and-dragging the area between the two. Does anyone have any tips
on how to do this? I tried adding a "-resizable => 1" option to the
TreeView, but that would have been too easy! (It didn't work, of
course). I imagine it makes use of the MouseOver et al. events, but
the documentation is a bit thin on those events. Do I have to put
another control (a 1-pixel-wide button perhaps?) between the two to
get at the events? As usual, an example would be worth a thousand words…
Use the Splitter control.
You beat me to it!
Perl Oasis uses this for an example:
http://user.bahnhof.se/~johanl/perl/Oasis/download.html
For a smaller and more focused example, download The GUI Loft
http://user.bahnhof.se/~johanl/perl/Loft/
and look at the Demo/FileDisplay(manual_resize) example. The purpose of
that demo is exactly what you're after.
For the record, here's a short example that shows it working with 2
Textfield controls.
Regards,
Rob.
#!perl -w
use strict;
use warnings;
use Win32::GUI;
my $mw = Win32::GUI::Window->new(
-title => "Splitter Test",
-pos => [100,100],
-size => [500,400],
-onResize => \&main_resize,
);
$mw->AddTextfield(
-name => "TF1",
-multiline => 1,
-width => 200,
);
$mw->AddSplitter(
-name => "SP",
-left => 200,
-width => 2,
-onRelease => \&do_splitter,
);
$mw->AddTextfield(
-name => "TF2",
-multiline => 1,
-left => 200 + $mw->SP->Width(),
);
$mw->Show();
Win32::GUI::Dialog();
exit(0);
# NEM splitter event gets 2 parameters. The first (as always)
# is the window object the wvwnt came from - in this case the
# splitter window; The second depends on the splitter orientation:
# if horzontal it is the top coordinate; if vertical it is
# the left coordinate. (coordinates relative to the parent's
# client area)
# The splitter window is moved by the splitter object, so you only
# have to re-position your other windows
sub do_splitter
{
my ($splitter, $coord) = @_;
$mw->TF1->Width($coord);
$mw->TF2->Move($coord+$mw->SP->Width(), 0);
$mw->TF2->Resize($mw->ScaleWidth()-$mw->SP->Width(),
$mw->ScaleHeight());
}
sub main_resize
{
my $self = shift;
$mw->TF1->Height($self->ScaleHeight());
$mw->SP->Height($self->ScaleHeight());
$mw->TF2->Resize($mw->ScaleWidth()-$self->TF1->Width()-$mw->SP->Width(),
$mw->ScaleHeight());
}
__END__
--
Robert May
Win32::GUI, a perl extension for native Win32 applications
http://perl-win32-gui.sourceforge.net/