private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref CharFormat2 lParem);
private static extern IntPtr SendMessageNative(IntPtr hwnd, int msg, IntPtr wParam, ref CharFormat2 lParam);
public static extern bool SendMessage(IntPtr hWnd, int Msg, int wParam, ref CharFormat2 lParam);
public void ClearBackColor(bool clearAll) { //LockWindowUpdate(HWND); this.SuspendRefresh(); this.SuspendScroll(); this.SuspendLayout(); int ScrollPosVert = this.HorizontalScrollPos; int ScrollPosHoriz = this.VerticalScrollPos; int selStart = this.SelectionStart; int selLength = this.SelectionLength; try { IntPtr HWND = this.Handle; if (clearAll) this.SelectAll(); CharFormat2 format = new CharFormat2(); format.crBackColor = -1; format.dwMask = CFM_BACKCOLOR; format.dwEffects = CFE_AUTOBACKCOLOR; format.cbSize = Marshal.SizeOf(format); SendMessage(HWND, EM_SETCHARFORMAT, SCF_SELECTION, ref format); } finally { // Return the previous values... this.SelectionStart = selStart; this.SelectionLength = selLength; this.HorizontalScrollPos = ScrollPosHoriz; this.VerticalScrollPos = ScrollPosVert; this.ResumeLayout(); //LockWindowUpdate(IntPtr.Zero); this.ResumeRefresh(); this.ResumeScroll(); } }
#pragma warning restore CA1838 // Avoid 'StringBuilder' parameters for P/Invokes public static IntPtr SendMessage(IntPtr hwnd, int msg, IntPtr wParam, ref CharFormat2 lParam) { return(SendMessageNative(hwnd, msg, wParam, ref lParam)); }
protected static extern bool SendMessage(IntPtr hWnd, int msg, int wParam, ref CharFormat2 lParam);
public extern static bool SendMessage(IntPtr hWnd, int Msg, int wParam, ref CharFormat2 lParam);
public static extern IntPtr SendMessage(IntPtr window, int msg, int wParam, ref CharFormat2 lParam);
public void ClearBackColor([Optional, DefaultParameterValue(true)] bool ClearAll) { CharFormat2 Format; IntPtr HWND = this.Handle; LockWindowUpdate(this.Handle); this.SuspendLayout(); int ScrollPosVert = this.GetScrollBarPos(this.Handle, ScrollBarTypes.SB_VERT); int ScrollPosHoriz = this.GetScrollBarPos(this.Handle, ScrollBarTypes.SB_HORZ); int SelStart = this.SelectionStart; int SelLength = this.SelectionLength; if (ClearAll) { this.SelectAll(); } Format = new CharFormat2(); Format.crBackColor = -1; Format.crTextColor = -1; Format.dwMask = 0x4000000; Format.dwEffects = 0x4000000; Format.cbSize = Marshal.SizeOf(Format); SendMessage(this.Handle, 0x444, 1, ref Format); this.SelectionStart = SelStart; this.SelectionLength = SelLength; SendMessage(this.Handle, 0x4de, 0, new POINT(ScrollPosHoriz, ScrollPosVert)); this.ResumeLayout(); LockWindowUpdate(IntPtr.Zero); }