private void SelectTheSource(int nWhich) { if (SelectedSource != 0) { DialogResult nReturn; nReturn = MessageBox.Show("For this demo, only one Source can be opened. Close current Source?", "DTWAIN Message", MessageBoxButtons.YesNo); if (nReturn == DialogResult.Yes) { TwainAPI.DTWAIN_CloseSource(SelectedSource); SelectedSource = 0; // EnableSourceItems( FALSE ); } else { return; } } this.Enabled = false; // disable the main form switch (nWhich) { case 0: // Select the source SelectedSource = TwainAPI.DTWAIN_SelectSource(); break; case 1: SelectSourceByNameBox objSelectSourceByName = new SelectSourceByNameBox(); DialogResult nResult = objSelectSourceByName.ShowDialog(); if (nResult == DialogResult.OK) { SelectedSource = TwainAPI.DTWAIN_SelectSourceByName(objSelectSourceByName.GetText()); } break; case 2: SelectedSource = TwainAPI.DTWAIN_SelectDefaultSource(); break; case 3: CustomSelectSource customSourceDlg = new CustomSelectSource(); DialogResult dResult = customSourceDlg.ShowDialog(); if (dResult == DialogResult.OK) { SelectedSource = TwainAPI.DTWAIN_SelectSourceByName(customSourceDlg.GetSourceName()); } break; } this.Enabled = true; // re-enable the main form if (SelectedSource != 0) { if (TwainAPI.DTWAIN_OpenSource(SelectedSource) != 0) { TwainAPI.DTWAIN_EnableFeeder(SelectedSource, 1); SetCaptionToSourceName(); EnableSourceItems(true); return; } else { MessageBox.Show("Error Opening Source", "TWAIN Error", MessageBoxButtons.OK); } } else { MessageBox.Show("Error Selecting Source", "TWAIN Error", MessageBoxButtons.OK); } EnableSourceItems(false); }