/// <summary> /// Sets the font only for the selected part of the rich text box /// without modifying the other properties like size or style /// </summary> /// <param name="face">Name of the font to use</param> /// <returns>true on success, false on failure</returns> public static bool SetSelectionFont(RichTextBox control, string face) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.szFaceName = new char[32]; cf.dwMask = CFM_FACE; face.CopyTo(0, cf.szFaceName, 0, Math.Min(31, face.Length)); IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); int res = SendMessage(control.Handle, EM_SETCHARFORMAT, SCF_SELECTION, lParam); return (res == 0); }
/// <summary> /// Set the style only for the selected part of the rich text box /// with the possibility to mask out some styles that are not to be modified /// </summary> /// <param name="mask">modify which styles?</param> /// <param name="effect">new values for the styles</param> /// <returns>true on success, false on failure</returns> private bool SetSelectionStyle(UInt32 mask, UInt32 effect) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.dwMask = mask; cf.dwEffects = effect; IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); int res = SendMessage(control.Handle, EM_SETCHARFORMAT, SCF_SELECTION, lParam); return(res == 0); }
/// <summary> /// Sets the font only for the selected part of the rich text box /// without modifying the other properties like size or style /// </summary> /// <param name="face">Name of the font to use</param> /// <returns>true on success, false on failure</returns> public bool SetSelectionFont(string face) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.szFaceName = new char[32]; cf.dwMask = CFM_FACE; face.CopyTo(0, cf.szFaceName, 0, Math.Min(31, face.Length)); IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); //Marshal.StructureToPtr(cf, lParam, false); int res = SendMessage(Handle, EM_SETCHARFORMAT, SCF_SELECTION, lParam); return(res == 0); }
/// <summary> /// Sets the font size only for the selected part of the rich text box /// without modifying the other properties like font or style /// </summary> /// <param name="size">new point size to use</param> /// <returns>true on success, false on failure</returns> public static bool SetSelectionSize(RichTextBox control, int size) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.dwMask = CFM_SIZE; // yHeight is in 1/20 pt cf.yHeight = size * 20; IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); int res = SendMessage(control.Handle, EM_SETCHARFORMAT, SCF_SELECTION, lParam); return(res == 0); }
public bool SetSelectionSize(int size) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.dwMask = CFM_SIZE; cf.yHeight = size * 20; IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); int res = Win32.SendMessage(Handle, (int)Win32.Msg.EM_SETCHARFORMAT, SCF_SELECTION, lParam); return(res == 0); }
private static extern int SendMessage(HandleRef hWnd, int msg, int wParam, ref CHARFORMATSTRUCT lp);
/// <summary> /// Sets the font size only for the selected part of the rich text box /// without modifying the other properties like font or style /// </summary> /// <param name="size">new point size to use</param> /// <returns>true on success, false on failure</returns> public static bool SetSelectionSize(RichTextBox control, int size) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.dwMask = CFM_SIZE; // yHeight is in 1/20 pt cf.yHeight = size * 20; IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); int res = SendMessage(control.Handle, EM_SETCHARFORMAT, SCF_SELECTION, lParam); return (res == 0); }
/// <summary> /// Set the style only for the selected part of the rich text box /// with the possibility to mask out some styles that are not to be modified /// </summary> /// <param name="mask">modify which styles?</param> /// <param name="effect">new values for the styles</param> /// <returns>true on success, false on failure</returns> private bool SetSelectionStyle(UInt32 mask, UInt32 effect) { CHARFORMATSTRUCT cf = new CHARFORMATSTRUCT(); cf.cbSize = Marshal.SizeOf(cf); cf.dwMask = mask; cf.dwEffects = effect; IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(cf)); Marshal.StructureToPtr(cf, lParam, false); int res = SendMessage(control.Handle, EM_SETCHARFORMAT, SCF_SELECTION, lParam); return (res == 0); }