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
Buddyβ€’3mo ago
Why are you not just subscribing to the scroll event?
Buddy
Buddyβ€’3mo 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?
βœ―πŸ’Ύ 𝑸𝒖𝒆𝒏𝒕 πŸ’Žβœ―  β–·πŸ“
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
Buddyβ€’3mo ago
Ugh. Winforms.
Buddy
Buddyβ€’3mo ago
Don't think there is a scroll event directly attached to WinForms TextBox
Buddy
Buddyβ€’3mo ago
or are you using RichTextBox?
Buddy
Buddyβ€’3mo 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
βœ―πŸ’Ύ 𝑸𝒖𝒆𝒏𝒕 πŸ’Žβœ―  β–·πŸ“
ok maybe is there any programm that migrates from winforms to wpf
Buddy
Buddyβ€’3mo 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