示例#1
0
文件: TextUtil.cs 项目: ewosp/sycorax
    public static Size GetTextSize( Graphics g, string text, Font font )
    {
      IntPtr hdc = GetGraphicsHDC( g );
      
      IntPtr hFont = font.ToHfont();
      IntPtr hOldFont = WindowsAPI.SelectObject( hdc, hFont );
      
      RECT rect = new RECT();
      WindowsAPI.DrawText( hdc, text, text.Length, ref rect, DEF_TEXTFORMAT );
      WindowsAPI.SelectObject( hdc, hOldFont );
      WindowsAPI.DeleteObject( hFont );

      ReleaseGraphicHDC( g, hdc );

      return ( Size )rect;
    }
示例#2
0
        public static void DrawText( Graphics graphics, string text, Font font, Rectangle rect )
        {
            IntPtr hdc = graphics.GetHdc();
              IntPtr fontHandle = font.ToHfont();
              IntPtr currentFontHandle = WindowsAPI.SelectObject(hdc, fontHandle);
              WindowsAPI.SetBkMode(hdc, BackgroundMode.TRANSPARENT);

              RECT rc = new RECT();
              rc.left = rect.Left;
              rc.top = rect.Top;
              rc.right = rc.left + rect.Width;
              rc.bottom = rc.top + rect.Height;

              WindowsAPI.DrawText(hdc, text, text.Length, ref rc,
            (int)(DrawTextFormatFlags.DT_SINGLELINE | DrawTextFormatFlags.DT_LEFT
            | DrawTextFormatFlags.DT_MODIFYSTRING| DrawTextFormatFlags.DT_WORD_ELLIPSIS));
              WindowsAPI.SelectObject(hdc, currentFontHandle);
              WindowsAPI.DeleteObject(fontHandle);
              graphics.ReleaseHdc(hdc);
        }
 public static extern int ValidateRect( IntPtr hWnd, ref RECT rc );
 public static extern int DrawText(IntPtr hdc, string lpString, int nCount, ref RECT lpRect, int uFormat);
   public static extern int ScrollWindowEx(IntPtr hWnd, int dx, int dy, 
 ref RECT rcScroll, ref RECT rcClip, IntPtr UpdateRegion, ref RECT rcInvalidated, uint flags);
 public static extern void SendMessage(IntPtr hWnd, int msg, int wParam, ref RECT lParam);
 public static extern int InvalidateRect(IntPtr hWnd,  ref RECT rect, int bErase);
 public static extern bool GetWindowRect(IntPtr hWnd, ref RECT rect);
 public static extern bool GetMenuItemRect(IntPtr hWnd, IntPtr hMenu, uint Item, ref RECT rc);
示例#10
0
 public static extern int GetClientRect(IntPtr hWnd, ref RECT rc);
示例#11
0
 public static extern int FillRect(IntPtr hDC, ref RECT rect, IntPtr hBrush);