/// <include file='doc\RichTextBox.uex' path='docs/doc[@for="RichTextBox.SetCharFormat"]/*' />
        /// <devdoc>
        /// </devdoc>
        /// <internalonly/>
        private bool SetCharFormat(int mask, int effect, RichTextBoxSelectionAttribute charFormat) {
            // check to see if the control has been created
            if (IsHandleCreated) {
                NativeMethods.CHARFORMATA cf = new NativeMethods.CHARFORMATA();

                cf.dwMask = mask;

                switch (charFormat) {
                    case RichTextBoxSelectionAttribute.All:
                        cf.dwEffects = effect;
                        break;
                    case RichTextBoxSelectionAttribute.None:
                        cf.dwEffects = 0;
                        break;
                    default:
                        throw new ArgumentException(SR.GetString(SR.UnknownAttr));
                }

                // set the format information
                return IntPtr.Zero != UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), RichTextBoxConstants.EM_SETCHARFORMAT, RichTextBoxConstants.SCF_SELECTION, cf);
            }
            return false;
        }
        private void SetCharFormatFont(bool selectionOnly, Font value) {
            ForceHandleCreate();
            NativeMethods.LOGFONT logfont = new NativeMethods.LOGFONT();

            FontToLogFont(value, logfont);

            byte[] bytesFaceName;

            int dwMask = RichTextBoxConstants.CFM_FACE | RichTextBoxConstants.CFM_SIZE | RichTextBoxConstants.CFM_BOLD |
                RichTextBoxConstants.CFM_ITALIC | RichTextBoxConstants.CFM_STRIKEOUT | RichTextBoxConstants.CFM_UNDERLINE |
                RichTextBoxConstants.CFM_CHARSET;

            int dwEffects = 0;
            if (value.Bold) dwEffects |= RichTextBoxConstants.CFE_BOLD;
            if (value.Italic) dwEffects |= RichTextBoxConstants.CFE_ITALIC;
            if (value.Strikeout) dwEffects |= RichTextBoxConstants.CFE_STRIKEOUT;
            if (value.Underline) dwEffects |= RichTextBoxConstants.CFE_UNDERLINE;

            if (Marshal.SystemDefaultCharSize == 1)            
            {
                bytesFaceName = Encoding.Default.GetBytes(logfont.lfFaceName);

                NativeMethods.CHARFORMATA cfA = new NativeMethods.CHARFORMATA();
                for (int i=0; i<bytesFaceName.Length; i++) cfA.szFaceName[i] = bytesFaceName[i];
                cfA.dwMask = dwMask;
                cfA.dwEffects = dwEffects;
                cfA.yHeight = (int) (value.SizeInPoints * 20);
                cfA.bCharSet = logfont.lfCharSet;
                cfA.bPitchAndFamily = logfont.lfPitchAndFamily;

                UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), RichTextBoxConstants.EM_SETCHARFORMAT, selectionOnly ? RichTextBoxConstants.SCF_SELECTION : RichTextBoxConstants.SCF_ALL, cfA);
            }
            else
            {
                bytesFaceName = Encoding.Unicode.GetBytes(logfont.lfFaceName);

                NativeMethods.CHARFORMATW cfW = new NativeMethods.CHARFORMATW();
                for (int i=0; i<bytesFaceName.Length; i++) cfW.szFaceName[i] = bytesFaceName[i];
                cfW.dwMask = dwMask;
                cfW.dwEffects = dwEffects;
                cfW.yHeight = (int) (value.SizeInPoints * 20);
                cfW.bCharSet = logfont.lfCharSet;
                cfW.bPitchAndFamily = logfont.lfPitchAndFamily;

                UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), RichTextBoxConstants.EM_SETCHARFORMAT, selectionOnly ? RichTextBoxConstants.SCF_SELECTION : RichTextBoxConstants.SCF_ALL, cfW);
            }
        }
 private NativeMethods.CHARFORMATA GetCharFormat(bool fSelection) {
     NativeMethods.CHARFORMATA cf = new NativeMethods.CHARFORMATA();
     UnsafeNativeMethods.SendMessage(new HandleRef(this, Handle), RichTextBoxConstants.EM_GETCHARFORMAT, fSelection ? RichTextBoxConstants.SCF_SELECTION : RichTextBoxConstants.SCF_DEFAULT, cf);
     return cf;
 }