views:

92

answers:

1

I'm outputting something to the textfield I created using Win32::GUI, like this:

$Object->AddTextfield(
        -name   => "Birthchart",
        -left   => 75,
        -top    => 90,
        -width  => 250,
        -height => 250,
        -vscroll =>1,
        -multiline => 1,
        -prompt => "Birthchart",         
    );


    {#do something here....
     }
$Object->Birthchart->Append($Content);

The problem is: it automatically takes me to the end of the output but I want to read the output from the beginning without having to scroll up. It's okay to scroll down later.

I can use the following code

$Object->Birthchart->GetFirstVisibleLine();

to obtain the number of the uppermost visible line, but how can I set the number of the uppermost visible line to 0?

The code $Object->Birthchart->ResetFirstVisibleLine() doesn't work.

Any suggestions? Thanks in advance.

Update

Tried the following code

$Object->Birthchart->ScrollPos(1,0);

But it still doesn't work. The scrollbar seems to be reset but I still have to click on the scrollbar to view the beginning of the textfield content.

+1  A: 

The fix to my problem:

my @sel =$Object->Birthchart->GetSel();
$Object->Birthchart->Append($Content);
$Object->Birthchart->SetSel(@sel);
$Object->Birthchart->ScrollCaret();
$Object->Birthchart->SetFocus();

The reason why ScrollPos seems to have reset the scrollbar position but the content hasn't been updated is because ScrollPos() only acts on the scrollbar. It does not update the content of the textfield.

Many thanks to Anonymous Monk @perlmonks.org :) and the original answer is here.

Mike