private void graphTabControl_SelectedIndexChanged(object sender, EventArgs e) { if (handler != null) { if (graphTabControl.SelectedIndex == 1) { // if preview tab has been selected, trigger export ImageExportToPreview(); int i = ((TabControl)sender).SelectedIndex; focusedCanvas = i == 1 ? previewCanvas : graphControl; focusedCanvas.Focus(); } } }