boat73 has asked for the wisdom of the Perl Monks concerning the following question:

I have the following code that works well and allows the user to resize the window in order to view the entire grid f it is larger than the initial grid size. My problem or question as it may be is this. How can I make it so that the window size can't exceed the size of the grid?
use strict; use Win32::GUI; use Win32::GUI::Grid; &buildarray; my ($Date, $Time, $Source, $Type, $Category, $EventID, $Username, $Com +puterName, $Description, @data); my ($computer, $date, $time, $source, $type, $cat, $evt, $user, $det); my $rowset = ($#data + 2); # main Window my $Window = new Win32::GUI::Window ( -title => "Win32::GUI::Grid test 1", -pos => [100, 100], -size => [400, 400], -name => "Window", ) or die "new Window"; # Grid Window my $Grid = new Win32::GUI::Grid ( -parent => $Window, -name => "Grid", -pos => [0, 0], ) or die "new Grid"; # Init Grid $Grid->SetEditable(1); $Grid->SetRows($rowset); $Grid->SetColumns(9); $Grid->SetFixedRows(1); $Grid->SetFixedColumns(1); $Grid->OnEditCopy(); #### Change default background color of column 0 to blue #$Grid->SetDefCellBackColor(0,1, '#0000FF'); # Fill Grid my $color = "color"; # Set Headings $Grid->SetCellFormat('0', '0', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '0',"Computer"); $Grid->SetCellFormat('0', '1', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '1',"Date"); $Grid->SetCellFormat('0', '2', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '2',"Time"); $Grid->SetCellFormat('0', '3', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '3',"Source"); $Grid->SetCellFormat('0', '4', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '4',"Type"); $Grid->SetCellFormat('0', '5', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '5',"Category"); $Grid->SetCellFormat('0', '6', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '6',"Event"); $Grid->SetCellFormat('0', '7', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '7',"User"); $Grid->SetCellFormat('0', '8', DT_CENTER|DT_WORDBREAK); $Grid->SetCellText('0', '8',"Details"); my $row = 1; my $col; foreach my $line (@data){ s/\s+//g; foreach ($computer, $date, $time, $source, $type, $cat, $evt, $user, + $det){ undef; } ($computer, $date, $time, $source, $type, $cat, $evt, $user, $det) = + (split(/\|/, $line)); $Grid->SetCellText($row, '0',$computer); $Grid->SetCellText($row, '1',$date); $Grid->SetCellText($row, '2',$time); $Grid->SetCellText($row, '3',$source); $Grid->SetCellText($row, '4',$type); $Grid->SetCellText($row, '5',$cat); $Grid->SetCellText($row, '6',$evt); $Grid->SetCellText($row, '7',$user); $Grid->SetCellText($row, '8',$det); if($type =~ /Error/i){ for $col (0..$Grid->GetColumns()) { $Grid->SetCellBkColor($row,$col, '#FF0000'); } } elsif($type =~ /Warning/i){ for $col (0..$Grid->GetColumns()) { $Grid->SetCellBkColor($row,$col, '#FF8C00'); } } elsif($type =~ /Information/i){ for $col (0..$Grid->GetColumns()) { $Grid->SetCellBkColor($row,$col, '#EEEE00'); } } $row++; } $Grid->AutoSize(); # Event loop $Window->Show(); Win32::GUI::Dialog(); # Main window event handler sub Window_Terminate { return -1; } sub Window_Resize { my ($width, $height) = ($Window->GetClientRect)[2..3]; $Grid->Resize ($width, $height); } sub buildarray{ #open (FILEHANDLE, "$datafile"); #@data = <FILEHANDLE>; #close (FILEHANDLE); push @data, "Computer1|Date1|Time1|Source1|Type1|Category1|Eve +nt1|User1|Details1"; push @data, "Computer2|Date2|Time2|Source2|Type2|Category2|Eve +nt2|User2|Details2"; push @data, "Computer3|Date3|Time3|Source3|Type3|Category3|Eve +nt3|User3|Details3"; push @data, "Computer4|Date4|Time4|Source4|Type4|Category4|Eve +nt4|User4|Details4"; push @data, "Computer5|Date5|Time5|Source5|Type5|Category5|Eve +nt5|User5|Details5"; push @data, "Computer6|Date6|Time6|Source6|Type6|Category6|Eve +nt6|User6|Details6"; push @data, "Computer7|Date7|Time7|Source7|Type7|Category7|Eve +nt7|User7|Details7"; push @data, "Computer8|Date8|Time8|Source8|Type8|Category8|Eve +nt8|User8|Details8"; push @data, "Computer9|Date9|Time9|Source9|Type9|Category9|Eve +nt9|User9|Details9"; push @data, "Computer10|Date10|Time10|Source10|Type10|Category +10|Event10|User10|Details10"; push @data, "Computer11|Date11|Time11|Source11|Type11|Category +11|Event11|User11|Details11"; push @data, "Computer12|Date12|Time12|Source12|Type12|Category +12|Event12|User12|Details12"; push @data, "Computer13|Date13|Time13|Source13|Type13|Category +13|Event13|User13|Details13"; push @data, "Computer14|Date14|Time14|Source14|Type14|Category +14|Event14|User14|Details14"; push @data, "Computer15|Date15|Time15|Source15|Type15|Category +15|Event15|User15|Details15"; push @data, "Computer16|Date16|Time16|Source16|Type16|Category +16|Event16|User16|Details16"; push @data, "Computer17|Date17|Time17|Source17|Type17|Category +17|Event17|User17|Details17"; push @data, "Computer18|Date18|Time18|Source18|Type18|Category +18|Event18|User18|Details18" }

Replies are listed 'Best First'.
Re: Win32::GUI::grid set max window size
by boat73 (Scribe) on Mar 01, 2005 at 16:04 UTC
    Changing the Window_Resize subroutine to this seems to have done the trick but I am open to any suggestions on improving the code. Thanks
    sub Window_Resize { if($Window->Height() >= ($Grid->GetVirtualHeight)){ $Window->Height($Grid->GetVirtualHeight + 38); } if($Window->Width() >= ($Grid->GetVirtualWidth)){ $Window->Width($Grid->GetVirtualWidth + 12); } my ($width, $height) = ($Window->GetClientRect)[2..3]; $Grid->Resize($Window->Width(), $Window->Height()); }