Last active
June 14, 2022 13:55
-
-
Save bjoerntx/1ed4507a52a27ad4ce188e29bb67b170 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private bool scrolling = false; | |
private void setScrollOffset() { | |
// remember old scroll location | |
var oldScrollLocation = textControl1.ScrollLocation; | |
// scroll to bottom to get max value | |
textControl1.ScrollLocation = new Point(0, int.MaxValue); | |
int scrollY = textControl1.ScrollLocation.Y; | |
// mirror the max value in custom scroll bar | |
vScrollBar1.Maximum = scrollY; | |
// restore scroll location | |
textControl1.ScrollLocation = oldScrollLocation; | |
} | |
private void textControl1_Changed(object sender, EventArgs e) { | |
setScrollOffset(); | |
} | |
private void textControl1_VScroll(object sender, EventArgs e) { | |
if (scrolling == true) | |
return; | |
// set the scroll location | |
if (textControl1.ScrollLocation.Y <= vScrollBar1.Maximum) { | |
vScrollBar1.Value = textControl1.ScrollLocation.Y; | |
vScrollBar1.SmallChange = 300; // fine tune speed here | |
vScrollBar1.LargeChange = 300; | |
} | |
} | |
private void vScrollBar1_Scroll(object sender, ScrollEventArgs e) { | |
// mirror the scroll location | |
scrolling = true; | |
textControl1.ScrollLocation = new Point(0, e.NewValue); | |
scrolling = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment