in reply to Re^2: Cursor at end of Richedit control
in thread Cursor at end of Richedit control

I finally dug out the one use I made of a RichEdit control, and I forgot a bit.

The final piece of the puzzle is that you need to scroll the window to make the appropriate part of the buffer visible:

$win-> reReport-> SetSel( $re->TextLength, $re_>TextLength ); $win-> reReport-> Scroll( 'bottom' ); ## Now the selection is off the top $win-> reReport-> Scroll( -10 ); ## Adjust for the size of window ## and the size of the font.

See also GetFirstVisibleLine() which can be useful if you are not moving all the way to one extremity or the other.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^4: Cursor at end of Richedit control
by briannz556 (Beadle) on Aug 18, 2007 at 19:54 UTC
    Sorry about being terse. On selecting an entry in a combobox called 'Parameter' I use the following code to populate a Richedit control:
    sub ::cbParameter_Change{defined(my $win = $Win32::GUI::Loft::window{H +allblacks} ) or return(1); my $fh; # general filehandle my $list = $win-> cbParameter-> GetLBText($win-> cbParameter-> Get +CurSel()); my $path = getdcwd()."\\Lists\\$list.txt"; if (!(-e $path)) { open($fh, ">$path"); close $fh; }; $win-> reReport-> Load($path, 1); }
    and I now wish - using your terminology - to "Give the richedit control the focus, so that the text cursor (otherwise known as the insertion point), appears with the richedit control" AND at the end of it. Hope that helps?

      Did you try the code above?

      This is what I meant by minimal, working test app. I just cribed it out of that old program that used a RichEdit control. Supply it with a filename on the command line and it will:

      1. Creates a main window containing a RichEdit control and both scrolbars.
      2. Load the file.
      3. Move the insertion point to the end of that file.
      4. And scroll the window to show the last 10 line above the insertion point.
      5. Sets the focus to the RichEdit control and displays the window.

      It should be easy enough to add the relevant bits to your existing app.

      #! perl -slw use strict; use Win32::GUI; my $main = Win32::GUI::Window->new( -width => 800, -height => 600, -name => 'Main', ); my $re = $main->AddRichEdit( -width => $main->ScaleWidth, -height => $main->ScaleHeight, -hscroll => 1, -vscroll => 1, ); $re->Load( $ARGV[ 0 ]||die( 'No file' ), 1 ); $re->SetSel( ( $re->TextLength() ) x 2 ); $re->Scroll( 'bottom' ); $re->Scroll( -10 ); $re->SetFocus; $main->Show(); Win32::GUI::Dialog(); exit; sub Main_Resize { $re->Resize( $main->ScaleWidth, $main->ScaleHeight ); }

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
      Thanks so muh for your help. From your kind responses and a little bit of searching I came up with:
      $win-> reReport-> SetFocus; $win-> reReport-> SetSel(-1,-1);
      which does the trick. Appreciate your time.

        And that works for you? Cos it doesn't for me.

        Using -1 is slightly easier than querying TextLength(), but without the Scroll(), it doesn't cause the selection to be visible if the file is longer than then window. At least not for me.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.