예제 #1
0
		Control SetCaret(TextArea textArea)
		{
			var control = new Button { Text = "Set Caret" };
			control.Click += (sender, e) => {
				textArea.CaretIndex = textArea.Text.Length / 2;
				textArea.Focus();
			};
			return control;
		}
예제 #2
0
		Control ReplaceSelected(TextArea textArea)
		{
			var control = new Button { Text = "Replace selected text" };
			control.Click += (sender, e) => {
				textArea.SelectedText = "Some inserted text!";
				textArea.Focus();
			};
			return control;
		}
예제 #3
0
		Control SelectAll(TextArea text)
		{
			var control = new Button { Text = "Select All" };
			control.Click += (sender, e) => {
				text.SelectAll();
				text.Focus();
			};
			return control;
		}
예제 #4
0
		Control SetSelectedText(TextArea textArea)
		{
			var control = new Button { Text = "Set selected text" };
			control.Click += (sender, e) => {
				var text = textArea.Text;
				// select the last half of the text
				textArea.Selection = new Range(text.Length / 2, text.Length / 2 + 1);
				textArea.Focus();
			};
			return control;
		}
예제 #5
0
        public NoteView(string dir)
        {
            directory = dir;
            notes = new List<Note>();

            ListBox = new ListBox { Style = "ListNative" };
            TextArea = new TextArea { Style = "TextConsole" };

            var updatingNote = false;

            TextArea.TextChanged += delegate
            {
                if (ListBox.SelectedIndex < 0)
                    return;
                var note = notes[ListBox.SelectedIndex];
                bool changed = note.Changed;
                note.Content = TextArea.Text;
                if (changed != note.Changed)
                    ListBox.Invalidate();
            };

            TextArea.SelectionChanged += delegate
            {
                if (ListBox.SelectedIndex < 0 || updatingNote)
                    return;
                notes[ListBox.SelectedIndex].Selection = TextArea.Selection;
            };

            ListBox.SelectedIndexChanged += delegate
            {
                if (ListBox.SelectedIndex < 0)
                    return;
                var note = notes[ListBox.SelectedIndex];
                updatingNote = true;
                TextArea.Text = note.Content;
                TextArea.Selection = note.Selection;
                TextArea.Focus();
                updatingNote = false;
            };
        }
예제 #6
0
        /// <summary>
        /// 查找字符串
        /// </summary>
        /// <param name="textArea"></param>
        /// <param name="findContent"></param>
        /// <param name="curIndex"></param>
        /// <param name="caseSensitive"></param>
        /// <param name="isUp"></param>
        public void FindText(TextArea textArea, string findContent, int curIndex, bool caseSensitive, bool isUp)
        {
            string searchText;
            
            // pre
            if (isUp)
            {
                searchText = textArea.Text.Substring(0, curIndex);
            }
            else
            {
                curIndex += textArea.Selection.Length();
                searchText = textArea.Text.Substring(curIndex);
            }
           
            if (!caseSensitive)
            {
                searchText = searchText.ToLower();
                findContent = findContent.ToLower();
            }

            // find
            var index = isUp
                ? searchText.LastIndexOf(findContent, StringComparison.Ordinal)
                : searchText.IndexOf(findContent, StringComparison.Ordinal);
            if (index != -1)
            {
                var selectionStart = isUp ? index : index + curIndex;
                textArea.Selection = new Range<int>(selectionStart, selectionStart + findContent.Length - 1);
                textArea.Focus();
            }
            else
            {
                MessageBox.Show(string.Format("Not Found \"{0}\" ", findContent));
            }
        }