frmGoToLine.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System;
  2. using System.Windows.Forms;
  3. namespace Demo.Forms
  4. {
  5. partial class FrmGoToLine : Form
  6. {
  7. public FrmGoToLine()
  8. {
  9. InitializeComponent();
  10. }
  11. private void button1_Click(object sender, EventArgs e)
  12. {
  13. int line;
  14. if (!int.TryParse(textBox1.Text, out line)) return;
  15. var curScintilla = PluginBase.GetCurrentScintilla();
  16. Win32.SendMessage(curScintilla, SciMsg.SCI_ENSUREVISIBLE, line - 1, 0);
  17. Win32.SendMessage(curScintilla, SciMsg.SCI_GOTOLINE, line - 1, 0);
  18. Win32.SendMessage(curScintilla, SciMsg.SCI_GRABFOCUS, 0, 0);
  19. }
  20. private void frmGoToLine_KeyDown(object sender, KeyEventArgs e)
  21. {
  22. if ((e.KeyData == Keys.Return) || (e.Alt && (e.KeyCode == Keys.G)))
  23. {
  24. button1.PerformClick();
  25. e.Handled = true;
  26. }
  27. else if (e.KeyData == Keys.Escape)
  28. {
  29. Win32.SendMessage(PluginBase.GetCurrentScintilla(), SciMsg.SCI_GRABFOCUS, 0, 0);
  30. }
  31. else if (e.KeyCode == Keys.Tab)
  32. {
  33. var next = GetNextControl((Control)sender, !e.Shift);
  34. while ((next == null) || (!next.TabStop)) next = GetNextControl(next, !e.Shift);
  35. next.Focus();
  36. e.Handled = true;
  37. }
  38. }
  39. private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
  40. {
  41. if (!char.IsDigit(e.KeyChar)
  42. && (e.KeyChar != '\b')
  43. && (e.KeyChar != '\t'))
  44. e.Handled = true;
  45. }
  46. void FrmGoToLineVisibleChanged(object sender, EventArgs e)
  47. {
  48. if (!Visible)
  49. {
  50. Win32.SendMessage(PluginBase.NppData._nppHandle, NppMsg.NPPM_SETMENUITEMCHECK, PluginBase.FuncItems.Items[PluginBase.IdFrmGotToLine]._cmdID, 0);
  51. }
  52. }
  53. }
  54. }