本文整理汇总了C#中System.Drawing.Rect.ToRectangle方法的典型用法代码示例。如果您正苦于以下问题:C# Rect.ToRectangle方法的具体用法?C# Rect.ToRectangle怎么用?C# Rect.ToRectangle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Rect
的用法示例。
在下文中一共展示了Rect.ToRectangle方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MoveActiveWindowToScreen
/// <summary>
/// Move window to new screen and scale it as necisarry
/// </summary>
/// <param name="newScreen"></param>
public static void MoveActiveWindowToScreen(Screen newScreen)
{
IntPtr handle = GetForegroundWindow();
Rect rect = new Rect();
GetWindowRect(handle, ref rect);
Rectangle childRect = rect.ToRectangle();
Screen currentScreen = GetScreenContainingWindow(childRect);
Rectangle currentWorkingArea = currentScreen.WorkingArea;
double xPosPercentage = (1.0*childRect.X - currentWorkingArea.X) / currentWorkingArea.Width;
double yPosPercentage = (1.0 * childRect.Y - currentWorkingArea.Y) / currentWorkingArea.Height;
int newX = (int)(newScreen.WorkingArea.X + newScreen.WorkingArea.Width * xPosPercentage);
int newY = (int)(newScreen.WorkingArea.Y + newScreen.WorkingArea.Height * yPosPercentage);
if (newScreen.WorkingArea.Width != currentScreen.WorkingArea.Width || newScreen.WorkingArea.Height != currentScreen.WorkingArea.Height)
{
//different size working area/resolution
//scale window to new resolution
double widthPercentage = 1.0 * (rect.Width - resizeOffset.X) / currentWorkingArea.Width;
double heightPercentage = 1.0 * (rect.Height - resizeOffset.Y) / currentWorkingArea.Height;
int newWidth = (int)(newScreen.WorkingArea.Width * widthPercentage);
int newHeight = (int)(newScreen.WorkingArea.Height * heightPercentage);
newWidth += resizeOffset.X;
newHeight += resizeOffset.Y;
MoveActiveWindowTo(newX, newY, newWidth, newHeight, false);
}
else
MoveActiveWindowTo(newX, newY, false);
}
示例2: GetScreenActiveWindowIsOn
/// <summary>
/// Returns the screen containing the currently active window
/// </summary>
/// <returns></returns>
public static Screen GetScreenActiveWindowIsOn()
{
IntPtr handle = GetForegroundWindow();
Rect rect = new Rect();
GetWindowRect(handle, ref rect);
Rectangle childRect = rect.ToRectangle();
return GetScreenContainingWindow(childRect);
}
示例3: MoveActiveWindowOffScreenInDirection
/// <summary>
/// Move this window off this screen in the given direction eg (1,0) for right.
/// </summary>
/// <param name="dir">Direction to move window in units of the active screens' resolution.</param>
public static void MoveActiveWindowOffScreenInDirection(Point dir)
{
if(Screen.AllScreens.Length==1)return;
IntPtr handle = GetForegroundWindow();
Rect rect = new Rect();
GetWindowRect(handle, ref rect);
Rectangle childRect = rect.ToRectangle();
Screen currentScreen = GetScreenContainingWindow(childRect);
Rectangle workingArea = currentScreen.WorkingArea;
childRect.Offset(workingArea.Width * dir.X, workingArea.Height * dir.Y);
Screen newScreen = GetScreenContainingWindow(childRect);
if (WrapLeftRightScreens)
{
if (newScreen == currentScreen)
{
if (dir.Y == 0)
{
if (dir.X == 1)//wrap right to left most
newScreen = GetLeftMostScreen();
else if (dir.X == -1)//wrap Left to right most
newScreen = GetRightMostScreen();
}
}
}
MoveActiveWindowToScreen(newScreen);
}
示例4: GetActiveWindowRelativeRectangleF
public static RectangleF GetActiveWindowRelativeRectangleF()
{
IntPtr handle = GetForegroundWindow();
Rect rect = new Rect();
GetWindowRect(handle, ref rect);
Rectangle childRect = rect.ToRectangle();
Rectangle workingSpace = GetScreenContainingWindow(childRect).WorkingArea;
float relativeX = 1f * (childRect.X - positionOffset.X - workingSpace.X) / workingSpace.Width;
float relativeY = 1f * (childRect.Y - positionOffset.Y - workingSpace.Y) / workingSpace.Height;
float relativeW = 1f * (childRect.Width - resizeOffset.X) / workingSpace.Width;
float relativeH = 1f * (childRect.Height - resizeOffset.Y) / workingSpace.Height;
return new RectangleF(relativeX, relativeY, relativeW, relativeH);
}