in reply to Re^2: How can I reset the vertical scroll position in Perl using Win32::GUI?
in thread How can I reset the vertical scroll position in Perl using Win32::GUI?

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 :)
  • Comment on Re^3: How can I reset the vertical scroll position in Perl using Win32::GUI?
  • Download Code

Replies are listed 'Best First'.
Re^4: How can I reset the vertical scroll position in Perl using Win32::GUI?
by Anonymous Monk on Dec 31, 2009 at 12:57 UTC

    I think I found a satisfactory technique. After (re)discovering it, I actually recall using it when I putzed around in VB6 I learned C or Perl. (Tested code follows.)

    my @sel = $textfield->GetSel(); $textfield->Append($content); $textfield->SetSel(@sel); $textfield->ScrollCaret(); $textfield->SetFocus();

    Here, you save the current selection, add text which move the caret and scrollbar, then reset the caret to the former position, and then scroll to the caret (the focus is optional). Each operation is extremely fast, so it looks seamless: the scrollbar grows to indicate the new document size, but the viewport of the text field is unchanged.

    You could use ->SetSel(0,0) to force the caret to the top, and then ->ScrollCaret to scroll there, but if you want the user to be able to look around the data while it's filling, saving and resetting caret position is optimal. (I've encountered apps in the wild which don't do that, and waiting for the data to stop coming in so you can read it is annoying).

    If there's a simpler way to prevent moving the caret or scroll position while changing the text field's contents, it isn't obvious either in the Win32::GUI XS code or in the MSDN docs realting to EM_* messages.

      Haha, this pesky problem is finally gone! LOL :D Thanks a lot, Anonymous Monk!! I really appreciate your help!! Thanks! The code works great and the explanation makes perfect sense ! Thanks!