From f20a026292e4bde034f0f583a1ca6512876d4aa2 Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 15 Jul 2019 08:24:16 +0000 Subject: [PATCH] Worked around a weird problem setting the scrollbar positions on Windows. --- src/MainForm.cs | 14 ++++++++++++++ src/MainForm.ui.cs | 14 ++++---------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/MainForm.cs b/src/MainForm.cs index 90ce6e5..570cc73 100644 --- a/src/MainForm.cs +++ b/src/MainForm.cs @@ -188,4 +188,18 @@ public partial class MainForm : Form mSearchResults.ResumeLayout( true ) ; mSearchResultsKey = key ; } + + private void setChartImagePanelScrollPos( int? hscrollPos, int? vscrollPos ) + { + // FUDGE! These need to be set twice to take effect on Windows :-/ + if ( hscrollPos != null ) { + mChartImagePanel.HorizontalScroll.Value = hscrollPos.Value ; + mChartImagePanel.HorizontalScroll.Value = hscrollPos.Value ; + } + if ( vscrollPos != null ) { + mChartImagePanel.VerticalScroll.Value = vscrollPos.Value ; + mChartImagePanel.VerticalScroll.Value = vscrollPos.Value ; + } + } + } diff --git a/src/MainForm.ui.cs b/src/MainForm.ui.cs index abbbc2c..cd0587f 100644 --- a/src/MainForm.ui.cs +++ b/src/MainForm.ui.cs @@ -225,8 +225,7 @@ public partial class MainForm : Form double prevRelScrollPosY = (double)prevScrollPosY / (double)prevMaxScrollY ; // resize and position the ChartImage - mChartImagePanel.HorizontalScroll.Value = 0 ; - mChartImagePanel.VerticalScroll.Value = 0 ; + setChartImagePanelScrollPos( 0, 0 ) ; Size prevChartImagePictureBoxSize = new Size( mChartImagePictureBox.Size.Width, mChartImagePictureBox.Size.Height ) ; mChartImagePictureBox.Size = new Size( width, height ) ; if ( width < availableWidth ) @@ -320,18 +319,14 @@ public partial class MainForm : Form { // update the scroll position if ( scrollX != null ) { - HScrollProperties hscroll = mChartImagePanel.HorizontalScroll ; int maxScrollX = ChartImagePanel_MaxScrollX() ; int scrollPos = Math.Max( 0, Math.Min( maxScrollX, scrollX.Value ) ) ; - hscroll.Value = scrollPos ; - hscroll.Value = scrollPos ; // nb: for Windows :shrug: + setChartImagePanelScrollPos( scrollPos, null ) ; } if ( scrollY != null ) { - VScrollProperties vscroll = mChartImagePanel.VerticalScroll ; int maxScrollY = ChartImagePanel_MaxScrollY() ; int scrollPos = Math.Max( 0, Math.Min( maxScrollY, scrollY.Value ) ) ; - vscroll.Value = scrollPos ; - vscroll.Value = scrollPos ; // nb: for Windows :shrug: + setChartImagePanelScrollPos( null, scrollPos ) ; } } @@ -351,8 +346,7 @@ public partial class MainForm : Form mChartImagePictureBox.Image = chartImage.image ; } else mChartImagePictureBox.Image = null ; - mChartImagePanel.HorizontalScroll.Value = 0 ; - mChartImagePanel.VerticalScroll.Value = 0 ; + setChartImagePanelScrollPos( 0, 0 ) ; mUserZoom = 1.0 ; doMainFormResize( null ) ; }