//public int TextHeightForWidth(string text, int width) //{ // // example from http://www.mobilepractices.com/2007/12/multi-line-graphicsmeasurestring.html // Win32.RECT rect = new Win32.RECT(0, 0, width, 0); // //var hFont = Font.ToHfont(); // //var oldHFont = Api.SelectObject(hDc, hFont); // int flags = Win32.DT_CALCRECT | Win32.DT_WORDBREAK; // DrawText(hDc, text, text.Length, ref bounds, flags); // Api.SelectObject(hDc, oldHFont); // Api.DeleteObject(hFont); // g.ReleaseHdc(hDc); // return bounds.Bottom - bounds.Top; //} public Size GetDrawTextSize(string text, int width, Win32.DT format) { Win32.RECT rect = new Win32.RECT(0, 0, width, 1); Win32.DrawText(_hdc, text, text.Length, ref rect, format | Win32.DT.CALCRECT); return new Size(rect.Width, rect.Height); }
public int FillRect(int x, int y, int w, int h, BrushGdi hbrush) { Win32.RECT rect = new Win32.RECT(x, y, w, h); return Win32.FillRect(_hdc, ref rect, (IntPtr)hbrush); }