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

I wanted to create a vertical scrolling text field within my main window, but wasn't sure about how to do it. I opted for using a multiline text field equal to the size of the main window. However, the scrollbar for the text field isn't visible and if the user is resizing the main window, the text field doesn't resize along with it. If the user enlarges the window the boundary of the text field is visible along with the scrollbar I specified for the textfield. Is there another way to make the entire main window a text field with scrolling abilities or am I so what correct? My intention was to have the main window contain output information for a user when running "ScanLogs".

Currently "ScanLogs" is just a subroutine that spits out status information to my textfield.

From reading all the documentation, it looks like I need to write a routine to handle scrolling, but, correct me if I'm wrong, it looks like the latest version handles scrolling.

I'm new to perl and this is my first attempt at creating a GUI. Thanks for all your help.

my $screen_width = Win32::GUI::GetSystemMetrics(0); my $screen_height = Win32::GUI::GetSystemMetrics(1); $MainMenu = new Win32::GUI::Menu( "&Setup" => "", " > &Configuration" => "Configuration", "&Tests" => "", " > &Scan Drive" => "ScanLogs", "&Help" => "Help", " > &Help" => "Usage", "E&xit" => "Exit", " > E&xit" => "QuitExit", ); $small_sh = $screen_height / 2; $small_sw = $screen_width / 2; my $Main = Win32::GUI::Window->new( -name => "Main", -title => "$program_name v$VERSION", -pos => [ 100, 100 ], -size => [ 600, 400 ], -height => $small_sh, -width => $small_sw, -vscroll => 0, -topmost => 0, -addstyle => WS_CLIPCHILDREN, -left => CW_USEDEFAULT, -menu => $MainMenu, ); our $Main_msgs = $Main->AddTextfield ( -name => "MainMsgs", -multiline => 1, -hscroll => 1, -vscroll => 1, -autohscroll => 1, -autovscroll => 1, -keepselection => 1, -addstyle => WS_CLIPCHILDREN, -left => CW_USEDEFAULT, -pos => [0,0], -size => [$small_sw,$small_sh], );

Replies are listed 'Best First'.
Re: Scrolling text in a Win32:GUI window
by kejohm (Hermit) on Aug 27, 2011 at 07:58 UTC

    When creating a window, the size specified is for the whole window, which includes the border, titlebar, and minimize, maximize and close buttons (known as the non-client area). When creating a control using this size, it will be bigger than the area of the window used to display controls (known as the client area). You can use the ScaleWidth() and ScaleHeight() methods to get the size of the client area of the window. So in order to create a textfield that takes up all of the window, you can do something like this:

    my $scalewidth = $Main->ScaleWidth(); my $scaleheight = $Main->ScaleHeight(); my $Main_msgs = $Main->AddTextfield( ... -size => [$scalewidth, $scaleheight], ... );

    In order to make the textfield resize as the window does, you need to respond to the window Resize event. This involves creating a subroutine that will be called by Win32::GUI when the event is triggered. Here is an example:

    # The sub is named for the control name and event name sub Main_Resize { my $scalewidth = $Main->ScaleWidth(); my $scaleheight = $Main->ScaleHeight(); $Main_msgs->Resize($scalewidth, $scaleheight); return 1; }

      Thanks for your help.