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
Buddy3d ago
Why are you not just subscribing to the scroll event?
ξQuentξ
how do i do that :/
Buddy
Buddy3d 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
Buddy3d ago
Ugh. Winforms.
ξQuentξ
i dunno i need to make something fast
Buddy
Buddy3d ago
Don't think there is a scroll event directly attached to WinForms TextBox
Buddy
Buddy3d ago
or are you using RichTextBox?
ξQuentξ
im using richtextbox
Buddy
Buddy3d 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
Buddy3d 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.
Want results from more Discord servers?
Add your server