本文整理汇总了C#中System.Windows.Forms.Control.RectangleToScreen方法的典型用法代码示例。如果您正苦于以下问题:C# Control.RectangleToScreen方法的具体用法?C# Control.RectangleToScreen怎么用?C# Control.RectangleToScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Control
的用法示例。
在下文中一共展示了Control.RectangleToScreen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindTopControl
public static Control FindTopControl(Control parent, Point screen_pt)
{
Control c = parent.GetChildAtPoint(parent.PointToClient(screen_pt));
if (c == null) {
if (parent.RectangleToScreen(new Rectangle(0, 0, parent.Width, parent.Height)).Contains(screen_pt))
return parent;
else
return null;
}
else
return FindTopControl(c, screen_pt);
}
示例2: Show
void Show(string title, string text, Control control, ICON icon = 0, double timeOut = 0, bool allowMulti = false, bool focus = false, short x = 0, short y = 0)
{
if (!allowMulti)
CloseAll();
if (x == 0 && y == 0)
{
x = (short)(control.RectangleToScreen(control.ClientRectangle).Left + control.Width / 2);
y = (short)(control.RectangleToScreen(control.ClientRectangle).Top + control.Height / 2);
}
TOOLINFO toolInfo = new TOOLINFO();
toolInfo.cbSize = (uint)Marshal.SizeOf(toolInfo);
toolInfo.uFlags = 0x20; // TTF_TRACK
toolInfo.lpszText = text;
IntPtr pToolInfo = Marshal.AllocCoTaskMem(Marshal.SizeOf(toolInfo));
Marshal.StructureToPtr(toolInfo, pToolInfo, false);
byte[] buffer = Encoding.UTF8.GetBytes(title);
buffer = buffer.Concat(new byte[] { 0 }).ToArray();
IntPtr pszTitle = Marshal.AllocCoTaskMem(buffer.Length);
Marshal.Copy(buffer, 0, pszTitle, buffer.Length);
hWnd = User32.CreateWindowEx(0x8, "tooltips_class32", "", 0xC3, 0, 0, 0, 0, control.Parent.Handle, (IntPtr)0, (IntPtr)0, (IntPtr)0);
User32.SendMessage(hWnd, 1028, (IntPtr)0, pToolInfo); // TTM_ADDTOOL
User32.SendMessage(hWnd, 1042, (IntPtr)0, (IntPtr)((ushort)x | ((ushort)y << 16))); // TTM_TRACKPOSITION
//User32.SendMessage(hWnd, 1043, (IntPtr)0, (IntPtr)0); // TTM_SETTIPBKCOLOR
//User32.SendMessage(hWnd, 1044, (IntPtr)0xffff, (IntPtr)0); // TTM_SETTIPTEXTCOLOR
User32.SendMessage(hWnd, 1056, (IntPtr)icon, pszTitle); // TTM_SETTITLE 0:None, 1:Info, 2:Warning, 3:Error, >3:assumed to be an hIcon. ; 1057 for Unicode
User32.SendMessage(hWnd, 1048, (IntPtr)0, (IntPtr)500); // TTM_SETMAXTIPWIDTH
User32.SendMessage(hWnd, 0x40c, (IntPtr)0, pToolInfo); // TTM_UPDATETIPTEXT; 0x439 for Unicode
User32.SendMessage(hWnd, 1041, (IntPtr)1, pToolInfo); // TTM_TRACKACTIVATE
Marshal.FreeCoTaskMem(pszTitle);
Marshal.DestroyStructure(pToolInfo, typeof(TOOLINFO));
Marshal.FreeCoTaskMem(pToolInfo);
if (focus)
control.Focus();
control.Enter += control_Event;
control.Leave += control_Event;
control.TextChanged += control_Event;
control.KeyPress += control_Event;
control.Click += control_Event;
control.LocationChanged += control_Event;
control.SizeChanged += control_Event;
control.VisibleChanged += control_Event;
if (control is DataGridView)
((DataGridView)control).CellBeginEdit += control_Event;
Control parent = control.Parent;
while(parent != null)
{
parent.VisibleChanged += control_Event;
parent = parent.Parent;
}
control.TopLevelControl.LocationChanged += control_Event;
((Form)control.TopLevelControl).Deactivate += control_Event;
timer.AutoReset = false;
timer.Elapsed += timer_Elapsed;
if (timeOut > 0)
{
timer.Interval = timeOut;
timer.Start();
}
}
示例3: getVisibleRectangle
public static Rectangle getVisibleRectangle(Control panel, Control insideControl)
{
Rectangle rect = panel.RectangleToScreen(panel.ClientRectangle);
while (panel != null)
{
rect = Rectangle.Intersect(rect, panel.RectangleToScreen(panel.ClientRectangle));
panel = panel.Parent;
}
rect = insideControl.RectangleToClient(rect);
return rect;
}
示例4: Rubberband
public Rubberband(System.Windows.Forms.Control theParent, Point theStartingPoint)
{
parent = theParent;
parent.Capture = true;
Cursor.Clip = parent.RectangleToScreen(parent.ClientRectangle);
rect = new Rectangle(theStartingPoint.X, theStartingPoint.Y, 0, 0);
}
示例5: GetPreviewBounds
/// <summary>
/// Get preview bounds
/// </summary>
/// <param name="dock">dock for which to get the preview bounds</param>
/// <param name="movedPanel">moved panel</param>
/// <param name="panelUnderMouse">panel under mouse</param>
/// <param name="freeAreaBounds">free area bounds</param>
/// <returns>preview bounds</returns>
public static Rectangle GetPreviewBounds(DockStyle dock, Control movedPanel, Control panelUnderMouse, Rectangle freeAreaBounds)
{
Rectangle bounds = freeAreaBounds;
if (panelUnderMouse != null)
{
bounds = panelUnderMouse.RectangleToScreen(panelUnderMouse.ClientRectangle);
}
switch (dock)
{
case DockStyle.Left:
return GetInnerLeftPreviewBounds(movedPanel, bounds);
case DockStyle.Right:
return GetInnerRightPreviewBounds(movedPanel, bounds);
case DockStyle.Top:
return GetInnerTopPreviewBounds(movedPanel, bounds);
case DockStyle.Bottom:
return GetInnerBottomPreviewBounds(movedPanel, bounds);
case DockStyle.Fill:
return GetInnerFillPreviewBounds(movedPanel, bounds);
default:
throw new InvalidOperationException();
}
}
示例6: Position
// xpos = +1 right, -1 left, 0 centre ypos = +1 top -1 bot 0 centre of parent
// yoffper xoffper = percentage of parent width to shift from indicated pos, can be negative
// widthper/heightper = percentage of parent width, or 0 to measure string and fit
public void Position(Control parent, int xpos, int xoffper, int ypos, int yoffper , int widthper, int heightper )
{
Rectangle loc = parent.RectangleToScreen( parent.ClientRectangle);
if (widthper == 0 || heightper == 0)
{
using (Graphics g = CreateGraphics())
{
SizeF sizef = g.MeasureString(labelMessage.Text, labelMessage.Font);
Rectangle screenRectangle = RectangleToScreen(this.ClientRectangle);
int titleHeight = screenRectangle.Top - this.Top;
Size = new Size((int)(sizef.Width + 16), (int)(sizef.Height + titleHeight + 16));
}
}
else
Size = new Size(loc.Width * widthper / 100, loc.Height * heightper / 100);
int xref = (xpos < 0) ? loc.Left : ((xpos > 0) ? loc.Right : (loc.X + loc.Width / 2));
int yref = (ypos < 0) ? loc.Bottom: ((ypos > 0) ? loc.Top : (loc.Y + loc.Height / 2));
xref += loc.Width * xoffper / 100;
yref += loc.Height * yoffper / 100;
Location = new Point(xref - Width / 2, yref - Height / 2);
labelMessage.Size = new Size(ClientRectangle.Width - 8, ClientRectangle.Height - 8);
}
示例7: PaintBackground
private void PaintBackground(Graphics g, Control control, Rectangle clipRect)
{
Control parent = control;
IPaintBackground asIpb = null;
while (true)
{
parent = parent.Parent;
if (parent == null)
{
break;
}
asIpb = parent as IPaintBackground;
if (asIpb != null)
{
break;
}
}
if (asIpb != null)
{
Rectangle screenRect = control.RectangleToScreen(clipRect);
Rectangle parentRect = parent.RectangleToClient(screenRect);
int dx = parentRect.Left - clipRect.Left;
int dy = parentRect.Top - clipRect.Top;
g.TranslateTransform(-dx, -dy, MatrixOrder.Append);
asIpb.PaintBackground(g, parentRect);
g.TranslateTransform(dx, dy, MatrixOrder.Append);
}
}
示例8: Dragger
public Dragger(Control theParent, Control theItemsToDrag, Point theStartingPoint)
{
parent = theParent;
ctr = theItemsToDrag;
location = theStartingPoint;
current = location;
// parent.Capture = true;
Cursor.Clip = parent.RectangleToScreen(parent.ClientRectangle);
}
示例9: ScreenObscurer
/// <summary>
/// Initialize a new instance of the ControlObscurer class.
/// </summary>
/// <param name="c">Control to obscure.</param>
/// <param name="designMode">Is the source in design mode.</param>
public ScreenObscurer(Control c, bool designMode)
{
// Check the incoming control is valid
if ((c != null) && !c.IsDisposed && !designMode)
{
// First time needed, create the top level obscurer window
if (_obscurer == null)
_obscurer = new ObscurerForm();
// We need a control to work with!
if (c != null)
_obscurer.ShowForm(c.RectangleToScreen(c.ClientRectangle));
}
}
示例10: ExcludeControlFromAeroGlass
/// <summary>
/// Excludes a Control from the AeroGlass frame.
/// </summary>
/// <param name="control">The control to exclude.</param>
/// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not
/// render properly on top of an AeroGlass frame. </remarks>
public void ExcludeControlFromAeroGlass( Control control )
{
if( AeroGlassCompositionEnabled )
{
Rectangle clientScreen = this.RectangleToScreen( this.ClientRectangle );
Rectangle controlScreen = control.RectangleToScreen( control.ClientRectangle );
MARGINS margins = new MARGINS( );
margins.cxLeftWidth = controlScreen.Left - clientScreen.Left;
margins.cxRightWidth = clientScreen.Right - controlScreen.Right;
margins.cyTopHeight = controlScreen.Top - clientScreen.Top;
margins.cyBottomHeight = clientScreen.Bottom - controlScreen.Bottom;
// Extend the Frame into client area
DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea( Handle, ref margins );
}
}
示例11: ExcludeControlFromAeroGlass
/// <summary>
/// Excludes a Control from the AeroGlass frame.
/// </summary>
/// <param name="control">The control to exclude.</param>
/// <remarks>Many non-WPF rendered controls (i.e., the ExplorerBrowser control) will not
/// render properly on top of an AeroGlass frame. </remarks>
public void ExcludeControlFromAeroGlass(Control control)
{
if (control == null) { throw new ArgumentNullException(nameof(control)); }
if (AeroGlassCompositionEnabled)
{
Rectangle clientScreen = this.RectangleToScreen(this.ClientRectangle);
Rectangle controlScreen = control.RectangleToScreen(control.ClientRectangle);
Margins margins = new Margins();
margins.LeftWidth = controlScreen.Left - clientScreen.Left;
margins.RightWidth = clientScreen.Right - controlScreen.Right;
margins.TopHeight = controlScreen.Top - clientScreen.Top;
margins.BottomHeight = clientScreen.Bottom - controlScreen.Bottom;
// Extend the Frame into client area
DesktopWindowManagerNativeMethods.DwmExtendFrameIntoClientArea(Handle, ref margins);
}
}
示例12: GetScreenClientRectangle
/// <summary>
/// Gets the client rectangle of given form
/// </summary>
/// <param name="form">form object</param>
/// <returns>client rectangle for given form</returns>
public static Rectangle GetScreenClientRectangle(Control form)
{
return form.RectangleToScreen(form.ClientRectangle);
}
示例13: ExcludeChildFromGlass
/// <summary>
/// Excludes the specified child control from the glass effect.
/// </summary>
/// <param name="parent">The parent control.</param>
/// <param name="control">The control to exclude.</param>
/// <exception cref="ArgumentNullException">Occurs if control is null.</exception>
/// <exception cref="ArgumentException">Occurs if control is not a child control.</exception>
public static void ExcludeChildFromGlass(this Control parent, Control control)
{
if (control == null)
throw new ArgumentNullException("control");
if (!parent.Contains(control))
throw new ArgumentException("Control must be a child control.");
if (IsCompositionEnabled())
{
System.Drawing.Rectangle clientScreen = parent.RectangleToScreen(parent.ClientRectangle);
System.Drawing.Rectangle controlScreen = control.RectangleToScreen(control.ClientRectangle);
Margins margins = new Margins(controlScreen.Left - clientScreen.Left, controlScreen.Top - clientScreen.Top,
clientScreen.Right - controlScreen.Right, clientScreen.Bottom - controlScreen.Bottom);
// Extend the Frame into client area
DwmExtendFrameIntoClientArea(parent.Handle, ref margins);
}
}
示例14: DrawXorBar
private static void DrawXorBar(Control ctlDrawTo, Rectangle rcFrame) {
Rectangle rc = ctlDrawTo.RectangleToScreen(rcFrame);
if (rc.Width < rc.Height) {
for (int i = 0; i < rc.Width; i++) {
ControlPaint.DrawReversibleLine(new Point(rc.X+i, rc.Y), new Point(rc.X+i, rc.Y+rc.Height), ctlDrawTo.BackColor);
}
}
else {
for (int i = 0; i < rc.Height; i++) {
ControlPaint.DrawReversibleLine(new Point(rc.X, rc.Y+i), new Point(rc.X+rc.Width, rc.Y+i), ctlDrawTo.BackColor);
}
}
}
示例15: GetBoundsControl
/// <summary>
/// Функция нормализует Rectangle Control (form)
/// </summary>
/// <param name="owner">Элемент под которым размещаемся!</param>
/// <param name="slave">Элемент, который размещаем!</param>
/// <returns></returns>
public static Rectangle GetBoundsControl(Control Owner,Control slave)
{
return GetBoundsControl(Owner.RectangleToScreen(Owner.Bounds),slave);
}