private void hexViewer1_onSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // in that case, move the selection in the ASM file as well
            Console.WriteLine("Selection in hexviewer: " + e.Offset.ToString("X8"));
            FileInfo fi     = new FileInfo(_motronicFile);
            int      offset = (int)fi.Length;

            if (offset == 0x20000)
            {
                offset = 0x60000;
            }

            int    address      = e.Offset + offset;
            string searchString = "0x" + address.ToString("X8");
            //_findForm.FindNext(true, false, string.Format("Search text «{0}» not found.", searchString));
            TextEditorSearcher _search = new TextEditorSearcher();

            _search.ClearScanRegion();
            _search.Document           = editor.Document;
            _search.LookFor            = searchString;
            _search.MatchCase          = true;
            _search.MatchWholeWordOnly = true;

            var       caret = editor.ActiveTextAreaControl.Caret;
            bool      _lastSearchLoopedAround = false;
            int       startFrom = 0;
            TextRange range     = _search.FindNext(startFrom, false, out _lastSearchLoopedAround);

            if (range != null)
            {
                SelectResult(range);
            }
            editor.Invalidate();
            editor.Refresh();
        }
        public void ShowFor(TextEditorControl editor, bool replaceMode)
        {
            Editor = editor;

            _search.ClearScanRegion();
            var sm = editor.ActiveTextAreaControl.SelectionManager;

            if (sm.HasSomethingSelected && sm.SelectionCollection.Count == 1)
            {
                var sel = sm.SelectionCollection[0];
                if (sel.StartPosition.Line == sel.EndPosition.Line)
                {
                    txtLookFor.Text = sm.SelectedText;
                }
                else
                {
                    _search.SetScanRegion(sel);
                }
            }
            else
            {
                // Get the current word that the caret is on
                Caret caret = editor.ActiveTextAreaControl.Caret;
                int   start = TextUtilities.FindWordStart(editor.Document, caret.Offset);
                int   endAt = TextUtilities.FindWordEnd(editor.Document, caret.Offset);
                txtLookFor.Text = editor.Document.GetText(start, endAt - start);
            }

            ReplaceMode = replaceMode;

            this.Owner = (Form)editor.TopLevelControl;
            this.Show();

            txtLookFor.SelectAll();
            txtLookFor.Focus();
        }