Scrolltocarret

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Scrolltocarret

Post by stevens »

Hi,

I have a function in the gui 'add-logs', which writes to a rich-textbox
It does the following:
$richtextboxMainfFormOutPutLogging.Text += $text
$richtextboxMainfFormOutPutLogging.ScrollToCaret()

It works fine but scrolls to the top whereas the lines (log) added are in the bottom of the richtextbox :-(
How can I address this?
Please advise

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Scrolltocarret

Post by jvierra »

You have to set the position of the caret with the "Select()" method. Set it to the length of the text.

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Re: Scrolltocarret

Post by stevens »

That's not the issue, I have already
$richtextLogging.SelectionStart = $richtextLogging.Text.Length
but the output is added at the bottom of the richtextbox whereas the focus is at the top of the richtextbox.
Not sure how I can do this with select()(?)

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Scrolltocarret

Post by jvierra »

That is not what I posted. You have to use "Select()" to set the caret. before you can scroll to it. "SelectionStart" is only used the user select with the mouse or keyboard.

See: https://docs.microsoft.com/en-us/dotnet ... stem_Int32_

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Re: Scrolltocarret

Post by stevens »

I have no clue howto set Select() with the length of the text.

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Scrolltocarret

Post by jvierra »

Did you read teh link I posted. It gives examples and definitions for the parameters. I suggest starting with that.

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Re: Scrolltocarret

Post by stevens »

Thanks, I did read that but still don't understand howto approach.

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Scrolltocarret

Post by jvierra »

What did you try?

jvierra
Posts: 14459
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Scrolltocarret

Post by jvierra »

Here is a sampler I found in my junk box. It demonstrates how to do many tings with text boxes and controls.
Attachments
Demo-RTFColors.psf
(22.45 KiB) Downloaded 12 times

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

Re: Scrolltocarret

Post by stevens »

Thanks, got it working!

Locked