Exemple #1
0
        /// <summary>
        /// Measures the specified string when drawn with the specified <see cref="OpenNETCF.Drawing.FontEx"/> object.
        /// </summary>
        /// <param name="text"><see cref="String"/> to measure.</param>
        /// <param name="font"><see cref="OpenNETCF.Drawing.FontEx"/> object that defines the text format of the string.</param>
        /// <returns></returns>
        public SizeF MeasureString(string text, FontEx font)
        {
            GDIPlus.SIZE sz       = new GDIPlus.SIZE();
            int          fit      = 0;
            IntPtr       hOldFont = GDIPlus.SelectObject(hDC, font.hFont);
            int          width    = 100;

            GDIPlus.GetTextExtentExPoint(hDC, text, text.Length, width, out fit, null, ref sz);
            GDIPlus.SelectObject(hDC, hOldFont);
            return(new SizeF(sz.width, sz.height));
        }
Exemple #2
0
        /// <summary>
        /// Measures the specified string when drawn with the specified <see cref="FontEx"/> object.
        /// </summary>
        /// <param name="text">String to measure.</param>
        /// <param name="font"><see cref="FontEx"/> object that defines the text format of the string.</param>
        /// <param name="width">Width to fit the string.</param>
        /// <returns></returns>
        public SizeF MeasureString(string text, FontEx font, int width)
        {
            //GDIPlus.SIZE sz = new GDIPlus.SIZE();
            IntPtr hdcTemp = GDIPlus.CreateCompatibleDC(hDC);
            IntPtr oldFont = GDIPlus.SelectObject(hdcTemp, font.hFont);

            GDIPlus.RECT rc = new GDIPlus.RECT();
            rc.right  = width;
            rc.bottom = 320;

            int height = GDIPlus.DrawText(hdcTemp, text, text.Length, ref rc,
                                          GDIPlus.DT_LEFT | GDIPlus.DT_TOP | GDIPlus.DT_WORDBREAK | GDIPlus.DT_CALCRECT);

            GDIPlus.SelectObject(hdcTemp, oldFont);
            GDIPlus.DeleteDC(hdcTemp);
            return(new SizeF(width, height));
        }
Exemple #3
0
 /// <summary>
 /// Draws the specified text string at the specified location with the specified <see cref="Color"/> and <see cref="FontEx"/> objects.
 /// </summary>
 /// <param name="text">String to draw</param>
 /// <param name="font"><see cref="FontEx"/> object that defines the text format of the string</param>
 /// <param name="textColor">The <see cref="Color"/> of text draw.</param>
 /// <param name="rc">Rectangle structure that specifies the location of the drawn text</param>
 public void DrawString(string text, FontEx font, Color textColor, Rectangle rc)
 {
     if (font.Angle == 0)
     {
         DrawText(hDC, font.hFont, text, text.Length, ref rc, GDIPlus.DT_LEFT | GDIPlus.DT_TOP | GDIPlus.DT_WORDBREAK, textColor, Color.Empty);
     }
     else if (font.Angle == 90)
     {
         DrawText(hDC, font.hFont, text, text.Length, ref rc, GDIPlus.DT_BOTTOM | GDIPlus.DT_LEFT, textColor, Color.Empty);
     }
     else if (font.Angle == 270)
     {
         DrawText(hDC, font.hFont, text, text.Length, ref rc, GDIPlus.DT_RIGHT | GDIPlus.DT_CENTER, textColor, Color.Empty);
     }
     else
     {
         DrawText(hDC, font.hFont, text, text.Length, ref rc, GDIPlus.DT_LEFT | GDIPlus.DT_TOP, textColor, Color.Empty);
     }
 }