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);
}
});
}
1 Reply
Is this WPF? Iirc there is a scroll changed event you can handle. If you do it this way, you don't need another thread to monitor and sync states.
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/controls/how-to-handle-the-scrollchanged-event?view=netframeworkdesktop-4.8
How to: Handle the ScrollChanged Event - WPF .NET Framework
Learn how to handle the ScrollChanged event, by means of the included code examples in XAML, C#, and Visual Basic.