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
Why are you not just subscribing to the scroll event?
how do i do that :/
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
Ugh. Winforms.
i dunno i need to make something fast
Don't think there is a scroll event directly attached to WinForms TextBox
oh
or are you using RichTextBox?
im using richtextbox
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
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.
ok