// an event handler for drag & drop for the naming instructions.. private void tbCommon_DragDrop(object sender, DragEventArgs e) { // if the data is of type of string set the effect to move.. if (e.Data.GetDataPresent(typeof(TagDescriptionPair)) && sender.Equals(activeTextBox)) // the sender must be one of the two formula text boxes.. { e.Effect = DragDropEffects.Move; // ensure a move effect.. TagDescriptionPair dropPair = (TagDescriptionPair)e.Data.GetData(typeof(TagDescriptionPair)); // set the text of the dropped item.. activeTextBox.SelectedText = dropPair.Tag; } }
// select the corresponding text from the active formula text box if the selected item // is contained within the text in the text box.. private void lbDragItems_SelectedIndexChanged(object sender, EventArgs e) { ListBox lb = (ListBox)sender; // the list box.. if (lb.SelectedItem != null) // check if an item is selected.. { TagDescriptionPair pair = (TagDescriptionPair)lb.SelectedItem; // get the selected item.. if (activeTextBox.Text.Contains(pair.Tag)) // if the text is there.. { // ..select the text.. activeTextBox.Select(activeTextBox.Text.IndexOf(pair.Tag, StringComparison.Ordinal), pair.Tag.Length); activeTextBox.Focus(); // set the focus to the text box.. } } }