How do i sync 2 Textbox Scrolling Positions i want to make a number counter:

private void StartParallelLoop() { Task.Run(() => { while (true) { Invoke(new Action(() => { NumberBar.SelectionStart = ScriptingPane.SelectionStart; NumberBar.ScrollToCaret(); // idk how to do that NumberBar.ZoomFactor = ScriptingPane.ZoomFactor; int lineCount = ScriptingPane.Text.Count(c => c == '\n') + 1; StringBuilder lineNumbers = new StringBuilder(); for (int i = 1; i <= lineCount; i++) { lineNumbers.AppendLine(i.ToString()); } NumberBar.Text = lineNumbers.ToString(); })); Thread.Sleep(100); } }); }
14 Replies
Buddy
Buddy2mo ago
Why are you not just subscribing to the scroll event?
ξQuentξ
how do i do that :/
Buddy
Buddy2mo ago
Also what does sync scroll have anything to do with a "number counter" ? You left out the detail of what framework you are using WPF, WinForms .. what?
ξQuentξ
this just means i use Winforms i use Winforms* and this means i want the scroll position of the number counter to be the same as the script pane's currently it sets the scroll at the end of the line which doesn't follow the script pane's scrolling position
Buddy
Buddy2mo ago
Ugh. Winforms.
ξQuentξ
i dunno i need to make something fast
Buddy
Buddy2mo ago
Don't think there is a scroll event directly attached to WinForms TextBox
ξQuentξ
oh
Buddy
Buddy2mo ago
or are you using RichTextBox?
ξQuentξ
im using richtextbox
Buddy
Buddy2mo ago
Check with using VScroll and HScroll events .. Though they're only for when you click the scrollbar, which is a pointless API tbh. In the future I highly suggest avoiding WinForms and use WPF if you want a modern Windows-only app. WinForms is +20 years old and legacy that barely supports transparency
ξQuentξ
ok maybe is there any programm that migrates from winforms to wpf
Buddy
Buddy2mo ago
Unfortunately not as it is two entirely different frameworks built very much differently and with WPF you should not use the designer at all but only edit the XAML similar to HTML.
ξQuentξ
ok
Want results from more Discord servers?
Add your server