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

Hi, Perl monks, This is the first time I've been here and I'm new to the rules here. Well, I'm asking a question I've already asked at stackoverflow.com. I'm not sure if this is okay and I don't want any duplicate efforts. But my question hasn't been answered there so I'm here anyway. The situation is this: 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? or just reset the scrollbar to the top position?

The code $Object->Birthchart->ResetFirstVisibleLine(); doesn't work. And I also tried the following code $Object->Birthchart->ScrollPos(1,0); 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.

Any ideas / suggestions? Thanks in advance.

Replies are listed 'Best First'.
Re: How can I reset the vertical scroll position in Perl using Win32::GUI?
by Anonymous Monk on Dec 31, 2009 at 09:49 UTC
    Once you've scrolled with ScrollPos (or Scroll and the SB_TOP keyword, see GUI.xs:1319), then I think you need to call ScrollCaret (see Textfield.xs:591). From msdn: "Scrolls the caret into view in an edit control."

      I just noticed another thing: in the text field Scroll method (Textfield.xs:524), the last thing the method does is to send EM_SCROLLCARET (Textfield.xs:586), which is the only thing that ScrollCaret does.

      On the other hand, ScrollPos only acts on the scrollbar, so it doesn't know what attached fields to update.

      If simply calling ScrollCaret doesn't work (I haven't tested it), passing SB_TOP to Scroll might.

        Anonymous Monk, Thanks a lot for taking the time to asnwer my question.

        Your explanation about ScrollPos makes very good sense. Thanks :) Now I understand when the scrollbar seems to be reset,why the textfield content isn't updated.

        With your suggestion, I tried adding
        $Object->Birthchart->Scroll(1,SB_TOP); $Object->Birthchart->ScrollCaret(); $Object->Birthchart->ScrollPos(1,0);
        But the problem persists. Where might I be doing wrong here? Thanks :)