diff --git a/MainForm.cs b/MainForm.cs index d2dddfc..a211982 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -21,6 +21,8 @@ private readonly Timer _uiTimer; private TabControl _tabs; + private TabPage _apertureTabPage; + private TabPage _focusTabPage; private PictureBox _focusPicture; private Label _focusCurrentValue; private Label _focusMaxValue; @@ -82,14 +84,14 @@ }; _tabs.DrawItem += Tabs_DrawItem; - TabPage focusPage = new TabPage("フォーカス調整"); - TabPage aperturePage = new TabPage("開口調整"); + _focusTabPage = new TabPage("フォーカス調整"); + _apertureTabPage = new TabPage("開口調整"); - BuildFocusPage(focusPage); - BuildAperturePage(aperturePage); + BuildFocusPage(_focusTabPage); + BuildAperturePage(_apertureTabPage); - _tabs.TabPages.Add(focusPage); - _tabs.TabPages.Add(aperturePage); + _tabs.TabPages.Add(_apertureTabPage); + _tabs.TabPages.Add(_focusTabPage); _tabs.SelectedIndex = 0; var statusStrip = new StatusStrip(); @@ -429,7 +431,7 @@ //Text = "フォーカス調整 \u2014 Lens Adjustment Tool"; _logger.Info("Application start."); RestoreApertureRoi(); - _processor.SetMode(AdjustmentMode.Focus, resetFocusMaximum: true); + ApplySelectedMode(clearMailbox: false); _camera.InitializeAndStart(AppDomain.CurrentDomain.BaseDirectory); _cameraInfoLabel.Text = _camera.CameraInfo?.ToString() ?? string.Empty; _uiTimer.Start(); @@ -450,12 +452,18 @@ private void Tabs_SelectedIndexChanged(object sender, EventArgs e) { - AdjustmentMode mode = _tabs.SelectedIndex == 0 - ? AdjustmentMode.Focus - : AdjustmentMode.Aperture; + ApplySelectedMode(clearMailbox: true); + } + + private void ApplySelectedMode(bool clearMailbox) + { + AdjustmentMode mode = GetSelectedMode(); _processor.SetMode(mode, resetFocusMaximum: mode == AdjustmentMode.Focus); - _mailbox.Clear(); + if (clearMailbox) + { + _mailbox.Clear(); + } if (mode == AdjustmentMode.Focus) { @@ -466,6 +474,13 @@ _logger.Info("Mode changed: " + mode); } + private AdjustmentMode GetSelectedMode() + { + return _tabs.SelectedTab == _focusTabPage + ? AdjustmentMode.Focus + : AdjustmentMode.Aperture; + } + private void FocusResetButton_Click(object sender, EventArgs e) { _processor.ResetFocusMaximum();