private void SetCharFormatFont(bool selectionOnly, System.Drawing.Font value) { byte[] bytes; this.ForceHandleCreate(); System.Windows.Forms.NativeMethods.LOGFONT logfont = new System.Windows.Forms.NativeMethods.LOGFONT(); FontToLogFont(value, logfont); int num = -1476394993; int num2 = 0; if (value.Bold) { num2 |= 1; } if (value.Italic) { num2 |= 2; } if (value.Strikeout) { num2 |= 8; } if (value.Underline) { num2 |= 4; } if (Marshal.SystemDefaultCharSize == 1) { bytes = Encoding.Default.GetBytes(logfont.lfFaceName); System.Windows.Forms.NativeMethods.CHARFORMATA lParam = new System.Windows.Forms.NativeMethods.CHARFORMATA(); for (int i = 0; i < bytes.Length; i++) { lParam.szFaceName[i] = bytes[i]; } lParam.dwMask = num; lParam.dwEffects = num2; lParam.yHeight = (int) (value.SizeInPoints * 20f); lParam.bCharSet = logfont.lfCharSet; lParam.bPitchAndFamily = logfont.lfPitchAndFamily; System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x444, selectionOnly ? 1 : 4, lParam); } else { bytes = Encoding.Unicode.GetBytes(logfont.lfFaceName); System.Windows.Forms.NativeMethods.CHARFORMATW charformatw = new System.Windows.Forms.NativeMethods.CHARFORMATW(); for (int j = 0; j < bytes.Length; j++) { charformatw.szFaceName[j] = bytes[j]; } charformatw.dwMask = num; charformatw.dwEffects = num2; charformatw.yHeight = (int) (value.SizeInPoints * 20f); charformatw.bCharSet = logfont.lfCharSet; charformatw.bPitchAndFamily = logfont.lfPitchAndFamily; System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x444, selectionOnly ? 1 : 4, charformatw); } }
private System.Windows.Forms.NativeMethods.CHARFORMATA GetCharFormat(bool fSelection) { System.Windows.Forms.NativeMethods.CHARFORMATA lParam = new System.Windows.Forms.NativeMethods.CHARFORMATA(); System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x43a, fSelection ? 1 : 0, lParam); return lParam; }
private bool SetCharFormat(int mask, int effect, RichTextBoxSelectionAttribute charFormat) { if (!base.IsHandleCreated) { return false; } System.Windows.Forms.NativeMethods.CHARFORMATA lParam = new System.Windows.Forms.NativeMethods.CHARFORMATA { dwMask = mask }; switch (charFormat) { case RichTextBoxSelectionAttribute.None: lParam.dwEffects = 0; break; case RichTextBoxSelectionAttribute.All: lParam.dwEffects = effect; break; default: throw new ArgumentException(System.Windows.Forms.SR.GetString("UnknownAttr")); } return (IntPtr.Zero != System.Windows.Forms.UnsafeNativeMethods.SendMessage(new HandleRef(this, base.Handle), 0x444, 1, lParam)); }