protected override void WndProc(ref System.Windows.Forms.Message m) { if (m.Msg == WM_KEYDOWN && Control.ModifierKeys == Keys.Control) { Keys keyData = (Keys)((int)m.WParam); if (this.altModeData.started) { if (keyData == Keys.C) { int cnt = 0; StringBuilder sb = new StringBuilder(); foreach (var line in this.altModeData.selBlocks) { if (++cnt > 1) { sb.Append("\r\n"); } sb.Append(this.Text.Substring(line.Key, line.Value)); } Clipboard.SetText(sb.ToString()); } } else // No Alt-selection mode { base.WndProc(ref m); } } else if (m.Msg == WM_MOUSEWHEEL && Control.ModifierKeys == Keys.Control) { appEventCallBack(TypeNotification.EDisableChangedNotification); var mwParam = (int)(long)m.WParam; if (mwParam > 0) { if (this.Font.Size < 72) { this.Font = new Font(this.Font.Name , this.Font.Size + 1, this.Font.Style); if (this.Focused == false) { this.Focus(); } } } else if (mwParam < 0) { if (this.Font.Size > 8) { this.Font = new Font(this.Font.Name , this.Font.Size - 1, this.Font.Style); if (this.Focused == false) { this.Focus(); } } } m.Result = (System.IntPtr) 1; appEventCallBack(TypeNotification.EEnableChangedNotification); } else // Some other wnd messages { base.WndProc(ref m); // http://stackoverflow.com/questions/14163007/catch-textbox-scroll-event if (m.Msg == WM_SIZE || m.Msg == WM_VSCROLL || m.Msg == WM_MOUSEWHEEL ) { if (this.mLightWordsQueue.Count > 0) { EScroll mode = EScroll.Page; int chTL = this.GetCharIndexFromPosition(new Point(0, Font.Height / 2)); int low = this.TopLeftChar > chTL ? SB_LINEUP : SB_LINEDOWN; this.TopLeftChar = chTL; switch (low) { case SB_LINEDOWN: mode = EScroll.DownLine; break; case SB_LINEUP: mode = EScroll.UpLine; break; } makeLighttening(mode); } } } }
void makeLighttening(EScroll mode) { int st = 0, fn = 0; switch (mode) { case EScroll.Page: st = this.GetCharIndexFromPosition(new Point(0, Font.Height / 2)); fn = this.GetCharIndexFromPosition(new Point(ClientRectangle.Width, ClientRectangle.Height)); break; case EScroll.DownLine: st = this.GetCharIndexFromPosition(new Point(0, ClientRectangle.Height / 2)); fn = this.GetCharIndexFromPosition(new Point(ClientRectangle.Width, ClientRectangle.Height)); break; case EScroll.UpLine: st = this.GetCharIndexFromPosition(new Point(0, Font.Height / 2)); fn = this.GetCharIndexFromPosition(new Point(ClientRectangle.Width, ClientRectangle.Height / 2)); break; } if (st >= fn) { return; } string check = selectedText; if (check.Length == 0 || false == Regex.IsMatch(check, "[\\w\\.\\-]+")) { return; } string wndText = this.Text.Substring(st, fn - st + 1); appEventCallBack(TypeNotification.EDisableChangedNotification); //SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero); // LockWindow(this.Handle); var matches = Regex.Matches(wndText, Utils.Utils.rgxScr(check) , RegexOptions.IgnoreCase); foreach (Match match in matches) { if (this.mLightWordsQueue.FirstOrDefault(x => x.Item1 == match.Index + st) != null) { continue; } char prevChar = (match.Index + st > 0) ? this.Text[match.Index + st - 1] : ' '; char nextChar = (match.Index + st + match.Length > this.Text.Length - 2) ? ' ' : this.Text[match.Index + st + match.Length]; bool isSubStr = char.IsLetterOrDigit(prevChar) || char.IsLetterOrDigit(nextChar); Color color; this.Select(match.Index + st, match.Length); this.mLightWordsQueue.Enqueue(Tuple.Create(match.Index + st, match.Length)); if (string.Compare(selectedText, match.Value) == 0) { if (isSubStr) { color = Color.Aquamarine; } else { color = Color.LightGreen; } } else { if (isSubStr) { color = Color.LightYellow; } else { color = Color.Yellow; } } this.SelectionBackColor = color; this.SelectionColor = Color.Black; } // LockWindow(IntPtr.Zero); // SendMessage(this.Handle, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero); this.Invalidate(); appEventCallBack(TypeNotification.EEnableChangedNotification); }