| Adding the Main GUI |
This page describes how to set up the main application form that is used to enter search strings and display the search results.
Apart from the main application form we will need other forms for selecting the TM and for configuring search settings. Therefore add a folder called GUI to your project that will contain all the application forms. Then add a form called frmLookup, which will be used to enter search strings and display results.
Add the following elements to your form:


Menu Functions
Clicking the menu items should open the corresponding form, i.e. the form for configuring the search settings:
private void searchOptionsToolStripMenuItem_Click(object sender, EventArgs e) { settings.Show(); }
Closing the Application
Clicking the Close button should exit the application:
private void btnClose_Click(object sender, EventArgs e) { Application.Exit(); }
Selecting the File-based TM
When the corresponding command in the context menu is clicked, you raise the open file dialog, in which the file TM can be selected. The complete file name is entered into the main application form, as is the TM language direction:
private void selectFileTMToolStripMenuItem_Click(object sender, EventArgs e) { // Raise open file dialog. this.openFileDialog.Title = "Select Translation Memory File"; this.openFileDialog.Filter = "Translation memories (*.sdltm)|*.sdltm"; // Check whether an *.sdltm file was selected if (this.openFileDialog.ShowDialog() == DialogResult.OK) { // Create a new connector object to connect to the file TM Connector fileConnect = new Connector(); fileConnect.SelectFileTm(this.openFileDialog.FileName); this.txtTmPath.Text = this.openFileDialog.FileName; // File TMs have only one language direction, which is filled into the // language pair list. string srcLang = Connector.fileTm.LanguageDirection.SourceLanguage.DisplayName.ToString(); string trgLang = Connector.fileTm.LanguageDirection.TargetLanguage.DisplayName.ToString(); this.comboLanguagePairs.Items.Clear(); this.comboLanguagePairs.Text = srcLang + " -> " + trgLang; } }
Raising the Form for Server TM Selection
Selecting a server TM requires users to enter more than just a file name and path. This is why the second command in the context menu raises a separate form, in which the server URI and user credentials are entered:
private void selectServerTMToolStripMenuItem_Click(object sender, EventArgs e) { frmSelectTM selectTm = new frmSelectTM(); selectTm.Show(); }
Initializing the Default Search Settings
When the application is started, the form for configuring the search settings should get the default settings, which - in our implementation - are identical to the settings used by SDL Trados Studio 2017, i.e. 70% as the minimum fuzzy match value and 30 as the maximum number of results that a concordance search should return. Note that both of these settings can have an impact on the search speed.
// Initialize form with default search settings. public frmLookup() { InitializeComponent(); frmSettings.maxHits = 30; frmSettings.minFuzzy = 70; }
Executing the Search
By clicking the Search button the corresponding function in the (yet to be implemented) Search class should be triggered. This function requires the search string (entered into the txtSearch text field, the source/target flag (as set through the comboIndex list) as parameters. In addition it requires the language pair index, which is provided by the comboLanguagePairs control element, as server TMs can have multiple language pairs:
private void btnSearch_Click(object sender, EventArgs e) { try { #region "SearchObject" Search search = new Search(); #endregion #region "SourceOrTarget" // Determine whether to do the concordance search in the // source or in the target language; bool searchTarget; if (this.comboIndex.Text == "Target") searchTarget = true; else searchTarget = false; #endregion #region "FillHitlist" // Fill the search result into the rich text box. this.lblHitCount.Text = search.DoConcordanceSearch(this.txtSearch.Text, searchTarget, comboLanguagePairs.SelectedIndex); #endregion } catch(Exception ex) { MessageBox.Show("No TM selected." + ex.Message); } }