コード例 #1
0
        internal NativeMethods.LOGFONT ToLOGFONT_Internal()
        {
            _LOGFONTW lfUnicode = this;

            // No way today to define a char array in IDL that is interop compatible, so
            // we've got to read everything in here!
            //
            StringBuilder sb = new StringBuilder();
            int           ch = 0;

            while (ch < 32)
            {
                FieldInfo fi = (typeof(_LOGFONTW)).GetField("lfFaceName" + ch.ToString());
                if (fi == null)
                {
                    break;
                }
                Object o = fi.GetValue(this);
                try {
                    short charVal = (short)o;
                    if (charVal == 0)
                    {
                        break;
                    }
                    sb.Append((char)charVal);
                }
                catch (InvalidCastException) {
                    return(null);
                }
                ch++;
            }

            // Copy one LOGFONT to the other...
            NativeMethods.LOGFONT lfAuto = new NativeMethods.LOGFONT();
            lfAuto.lfHeight         = lfUnicode.lfHeight;
            lfAuto.lfWidth          = lfUnicode.lfWidth;
            lfAuto.lfEscapement     = lfUnicode.lfEscapement;
            lfAuto.lfOrientation    = lfUnicode.lfOrientation;
            lfAuto.lfWeight         = lfUnicode.lfWeight;
            lfAuto.lfItalic         = lfUnicode.lfItalic;
            lfAuto.lfUnderline      = lfUnicode.lfUnderline;
            lfAuto.lfStrikeOut      = lfUnicode.lfStrikeOut;
            lfAuto.lfCharSet        = lfUnicode.lfCharSet;
            lfAuto.lfOutPrecision   = lfUnicode.lfOutPrecision;
            lfAuto.lfClipPrecision  = lfUnicode.lfClipPrecision;
            lfAuto.lfQuality        = lfUnicode.lfQuality;
            lfAuto.lfPitchAndFamily = lfUnicode.lfPitchAndFamily;
            lfAuto.lfFaceName       = sb.ToString();

            return(lfAuto);
        }