|
/////////////////////////////////////////////////////////////////////////////
//
// (c) 2007 BinaryComponents Ltd. All Rights Reserved.
//
// http://www.binarycomponents.com/
//
/////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Text;
using BinaryComponents.Utility.Win32;
using System.Windows.Forms;
using System.Drawing;
namespace BinaryComponents.WinFormsUtility.Controls
{
public static class ControlUtils
{
/// <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 Point FixForScreen( Rectangle rect )
{
Screen buttonScreen = Screen.PrimaryScreen;
Screen menuScreen = Screen.PrimaryScreen;
foreach( Screen screen in Screen.AllScreens )
{
if( screen.Bounds.Contains( rect ) )
{
buttonScreen = screen;
}
}
int x = rect.Left, y = rect.Bottom;
if( x + rect.Width > buttonScreen.WorkingArea.Right )
{
x = buttonScreen.WorkingArea.Right - rect.Width;
}
if( y + rect.Height > buttonScreen.WorkingArea.Bottom )
{
y = buttonScreen.WorkingArea.Bottom - rect.Height;
}
return new Point( x, y );
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm currently working for a small start-up company, BinaryComponents Ltd, producing the FeedGhost RSS reader.
FeedGhost RSS Reader:
http://www.feedghost.com
Bespoke Software Development
http://www.binarycomponents.com