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.
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Scrolltocarret

Post by stevens »

I have no clue howto set Select() with the length of the text.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Scrolltocarret

Post by stevens »

Thanks, I did read that but still don't understand howto approach.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scrolltocarret

Post by jvierra »

What did you try?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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 129 times
User avatar
stevens
Posts: 493
Last visit: Mon Sep 19, 2022 12:23 am
Has voted: 2 times

Re: Scrolltocarret

Post by stevens »

Thanks, got it working!
This topic is 3 years and 11 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked