/// <summary> /// Returns true if any part of the client based rectangle is visible. /// </summary> /// <param name="control">Control to check.</param> /// <param name="rectangleToCheck">Client based rectangle to check.</param> public static bool IsClientRectangleVisible( Control control, Rectangle rectangleToCheck ) { if( !control.IsHandleCreated ) { return false; } Utility.Win32.Common.RECT rcClip, rcClient = new Utility.Win32.Common.RECT( rectangleToCheck ); using( Graphics grfx = control.CreateGraphics() ) { IntPtr hdc = IntPtr.Zero; try { hdc = grfx.GetHdc(); RegionValue result = (RegionValue) Gdi.GetClipBox( hdc, out rcClip ); return result != RegionValue.NULLREGION; } finally { if( hdc != IntPtr.Zero ) { grfx.ReleaseHdc( hdc ); } } } }
/// <summary> /// Returns true if any part of the client based rectangle is visible. /// </summary> /// <param name="control">Control to check.</param> /// <param name="rectangleToCheck">Client based rectangle to check.</param> public static bool IsClientRectangleVisible(Control control, Rectangle rectangleToCheck) { if (!control.IsHandleCreated) { return(false); } Utility.Win32.Common.RECT rcClip, rcClient = new Utility.Win32.Common.RECT(rectangleToCheck); using (Graphics grfx = control.CreateGraphics()) { IntPtr hdc = IntPtr.Zero; try { hdc = grfx.GetHdc(); RegionValue result = (RegionValue)Gdi.GetClipBox(hdc, out rcClip); return(result != RegionValue.NULLREGION); } finally { if (hdc != IntPtr.Zero) { grfx.ReleaseHdc(hdc); } } } }
public static Size MeasureString( Graphics g, string text, Font font, int width ) { Size size; TextDetails td = new TextDetails( text, font, width ); if( _mapTextSizes.TryGetValue( td, out size ) ) { return size; } IntPtr hDC = g.GetHdc(); try { IntPtr hFont = font.ToHfont(); try { IntPtr hOldFont = Gdi.SelectObject( hDC, hFont ); try { Rectangle rect = new Rectangle( 0, 0, width, 0 ); Utility.Win32.Common.RECT r = new Utility.Win32.Common.RECT( rect ); Utility.Win32.User.DrawTextFlags uFormat = Utility.Win32.User.DrawTextFlags.DT_WORDBREAK | Utility.Win32.User.DrawTextFlags.DT_CALCRECT; Utility.Win32.User.DrawText( hDC, text, text.Length, ref r, uFormat ); size = new Size( r.Right, r.Bottom ); _mapTextSizes[td] = size; return size; } finally { Gdi.SelectObject( hDC, hOldFont ); } } finally { Gdi.DeleteObject( hFont ); } } finally { g.ReleaseHdc( hDC ); } }