protected override bool ProcessDialogKey(Keys keyData) { switch (keyData) { case Keys.Right: if ((int)(char_index_at_caret - screen_first_char) == text_area.CharsFitted - 1) { //нужен скролл на строку вниз scroll_line_down(); } caret_set_position(char_index_at_caret + 1); selection_reset(true); return(true); case Keys.Left: if (char_index_at_caret == screen_first_char) { //скролл вверх scroll_line_up(); } selection_reset(true); caret_set_position(char_index_at_caret - 1); return(true); case Keys.Down: var target_down_point = Caret.GetCaretPos(); target_down_point.Y = target_down_point.Y + (int)Math.Ceiling(text_area.Font.GetHeight()); if (text_area.GetLineBounds(text_area.LinesCount - 1).Y < target_down_point.Y) { //скролл вниз scroll_line_down(); //target_down_point = Caret.GetCaretPos(); } caret_set_position(target_down_point); selection_reset(true); return(true); case Keys.Up: var target_up_point_1 = Caret.GetCaretPos(); var target_up_point_2 = Caret.GetCaretPos(); target_up_point_2.Y = target_up_point_1.Y - (int)Math.Ceiling(text_area.Font.GetHeight()); if (target_up_point_2.Y < text_area.Bounds.Y) { scroll_line_up(); target_up_point_2 = target_up_point_1; } caret_set_position(target_up_point_2); selection_reset(true); return(true); case Keys.PageUp: selection_reset(); scroll_page_up(); caret_set_position(screen_first_char); return(true); case Keys.PageDown: selection_reset(); scroll_page_down(); caret_set_position(screen_first_char); return(true); case Keys.Home: selection_reset(); scroll_to_char(0); caret_set_position(screen_first_char); return(true); case Keys.End: selection_reset(); var target_char = text_provider.GetCharsCount(); target_char = target_char - 16; if (target_char < 0) { target_char = 0; } scroll_to_char(target_char); caret_set_position(target_char); return(true); case Keys.Shift | Keys.Right: if (selection_last == char_index_at_caret) { //продолжаем выделение selection_set(selection_first, char_index_at_caret + 1); } else { //начинаем новое selection_set(char_index_at_caret, char_index_at_caret + 1); } if ((int)(char_index_at_caret - screen_first_char) == text_area.CharsFitted - 1) { //нужен скролл на строку вниз scroll_line_down(); } caret_set_position(char_index_at_caret + 1); return(true); case Keys.Shift | Keys.Left: if (selection_first == char_index_at_caret) { //продолжаем выделение влево selection_set(char_index_at_caret - 1, selection_last); } else { //начианем новое selection_set(char_index_at_caret - 1, char_index_at_caret); } if (char_index_at_caret == screen_first_char) { //скролл вверх scroll_line_up(); } caret_set_position(char_index_at_caret - 1); return(true); case Keys.Shift | Keys.Down: var old_char_caret = char_index_at_caret; var target_down_point_shift = Caret.GetCaretPos(); target_down_point_shift.Y = target_down_point_shift.Y + (int)Math.Ceiling(text_area.Font.GetHeight()); if (text_area.GetLineBounds(text_area.LinesCount - 1).Y < target_down_point_shift.Y) { //скролл вниз scroll_line_down(); //target_down_point = Caret.GetCaretPos(); } caret_set_position(target_down_point_shift); if (selection_last == old_char_caret) { //продолжаем выделение selection_set(selection_first, char_index_at_caret); } else { //начинаем новое selection_set(old_char_caret, char_index_at_caret); } return(true); case Keys.Shift | Keys.Up: var old_char_caret_2 = char_index_at_caret; var target_up_point_1_shift = Caret.GetCaretPos(); var target_up_point_2_shift = Caret.GetCaretPos(); target_up_point_2_shift.Y = target_up_point_1_shift.Y - (int)Math.Ceiling(text_area.Font.GetHeight()); if (target_up_point_2_shift.Y < text_area.Bounds.Y) { scroll_line_up(); target_up_point_2_shift = target_up_point_1_shift; } caret_set_position(target_up_point_2_shift); if (selection_first == old_char_caret_2) { //продолжаем выделение selection_set(char_index_at_caret, selection_last); } else { //начинаем новое selection_set(char_index_at_caret, old_char_caret_2); } return(true); //case Keys.S: // scroll_line_down(); // return true; //case Keys.W: // scroll_line_up(); // return true; //case Keys.D: // scroll_page_down(); // return true; //case Keys.E: // scroll_page_up(); // return true; //case Keys.T: // text_area.FindPreviousLineStart(CreateGraphics()); // return true; /* * editing */ case Keys.Delete: if (EditEnable) { text_edit_provider.DeleteChars(char_index_at_caret, 1); Invalidate(); } return(true); case Keys.Back: if ((EditEnable) && (char_index_at_caret >= 1)) { text_edit_provider.DeleteChars(char_index_at_caret - 1, 1); Refresh(); caret_set_position(char_index_at_caret - 1); } return(true); case Keys.Control | Keys.Delete: if ((EditEnable) && (selection_last - selection_first > 0)) { text_edit_provider.DeleteChars(selection_first, selection_last - selection_first); Invalidate(); } return(true); } return(base.ProcessDialogKey(keyData)); }
protected override void OnLostFocus(EventArgs e) { Caret.DestroyCaret(); base.OnLostFocus(e); }