本文整理汇总了C#中System.Windows.Forms.Form.RectangleToScreen方法的典型用法代码示例。如果您正苦于以下问题:C# Form.RectangleToScreen方法的具体用法?C# Form.RectangleToScreen怎么用?C# Form.RectangleToScreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Form
的用法示例。
在下文中一共展示了Form.RectangleToScreen方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddButtonsToForm
private static void AddButtonsToForm(Form msgBoxFrm, MessageBoxButtons buttons)
{
Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
int titleHeight = screenRectangle.Top - msgBoxFrm.Top;
var t = Type.GetType("Mono.Runtime");
if ((t != null))
titleHeight = 25;
switch (buttons)
{
case MessageBoxButtons.OK:
var but = new MyButton
{
Size = new Size(75, 23),
Text = "OK",
Left = msgBoxFrm.Width - 100 - FORM_X_MARGIN,
Top = msgBoxFrm.Height - 40 - FORM_Y_MARGIN - titleHeight
};
but.Click += delegate { _state = DialogResult.OK; msgBoxFrm.Close(); };
msgBoxFrm.Controls.Add(but);
msgBoxFrm.AcceptButton = but;
break;
case MessageBoxButtons.YesNo:
if (msgBoxFrm.Width < (75 * 2 + FORM_X_MARGIN * 3))
msgBoxFrm.Width = (75 * 2 + FORM_X_MARGIN * 3);
var butyes = new MyButton
{
Size = new Size(75, 23),
Text = "Yes",
Left = msgBoxFrm.Width - 75 * 2 - FORM_X_MARGIN * 2,
Top = msgBoxFrm.Height - 23 - FORM_Y_MARGIN - titleHeight
};
butyes.Click += delegate { _state = DialogResult.Yes; msgBoxFrm.Close(); };
msgBoxFrm.Controls.Add(butyes);
msgBoxFrm.AcceptButton = butyes;
var butno = new MyButton
{
Size = new Size(75, 23),
Text = "No",
Left = msgBoxFrm.Width - 75 - FORM_X_MARGIN,
Top = msgBoxFrm.Height - 23 - FORM_Y_MARGIN - titleHeight
};
butno.Click += delegate { _state = DialogResult.No; msgBoxFrm.Close(); };
msgBoxFrm.Controls.Add(butno);
msgBoxFrm.CancelButton = butno;
break;
default:
throw new NotImplementedException("Only MessageBoxButtons.OK and YesNo supported at this time");
}
}
示例2: Capture
public virtual Bitmap Capture(Form window, bool onlyClient)
{
if (!onlyClient)
return this.Capture(window);
Rectangle rc = window.RectangleToScreen(window.ClientRectangle);
return this.capture(window, rc);
}
示例3: Capture
/// <summary>
/// Captures the specified form from the screen including any overlapped windows.
/// </summary>
/// <param name="form">The form to capture</param>
/// <param name="clientArea">If only the client area (non-chrome area) should be captured.</param>
/// <returns>An image with the form captured on it.</returns>
public static Bitmap Capture(Form form, bool clientArea)
{
return Capture(clientArea ? form.RectangleToScreen(form.ClientRectangle) : form.Bounds);
}
示例4: Draw
/// <summary>
/// Draws the form to a bitmap.
/// </summary>
/// <param name="form">The form to draw.</param>
/// <param name="clientArea">If only the client area (non-chrome area) should be drawn.</param>
/// <returns>An image with the form drawn onto it.</returns>
/// <remarks>Internally uses WM_PRINT to draw the form to an HDC.</remarks>
public static Bitmap Draw(Form form, bool clientArea)
{
Bitmap bmp = new Bitmap(form.Width, form.Height);
form.DrawToBitmap(bmp, new Rectangle(0, 0, form.Width, form.Height));
if (clientArea)
{
Bitmap crop = new Bitmap(form.ClientRectangle.Width, form.ClientRectangle.Height);
using (Graphics g = Graphics.FromImage(crop))
{
Rectangle screenRectangle = form.RectangleToScreen(form.ClientRectangle);
int titleHeight = screenRectangle.Top - form.Top;
g.DrawImage(bmp, new Point((form.ClientRectangle.Width - form.Width) / 2, -titleHeight));
}
bmp.Dispose();
bmp = crop;
}
return bmp;
}
示例5: DrawTrackerRect
public virtual void DrawTrackerRect(Rectangle Rect, Form ClipToFrm,Graphics gs,Control frm)
{
Rectangle rect = Rect;
// convert to client coordinates
if (ClipToFrm != null)
{
rect=ClipToFrm.RectangleToScreen(rect);
rect=ClipToFrm.RectangleToClient(rect);
}
Size size=new Size(0, 0);
if (!m_bFinalErase)
{
// otherwise, size depends on the style
if ((m_nStyle & StyleFlags.hatchedBorder)!=0)
{
size.Width = size.Height = Math.Max(1, GetHandleSize(rect)-1);
rect.Inflate(size);
}
else
{
size.Width = CX_BORDER;
size.Height = CY_BORDER;
}
}
if (m_bFinalErase || !m_bErase)
{
Rectangle rcScreen = frm.RectangleToScreen(rect);
Rectangle rcLast = frm.RectangleToScreen(m_rectLast);
DrawDragRect(gs,rcScreen,rcLast);
}
// remember last rectangles
m_rectLast = rect;
m_sizeLast = size;
}
示例6: ShowUI
static DialogResult ShowUI(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
if (text == null)
text = "";
if (caption == null)
caption = "";
string link = "";
string linktext = "";
Regex linkregex = new Regex(@"(\[link;([^\]]+);([^\]]+)\])", RegexOptions.IgnoreCase);
Match match = linkregex.Match(text);
if (match.Success)
{
link = match.Groups[2].Value;
linktext = match.Groups[3].Value;
text = text.Replace(match.Groups[1].Value, "");
}
// ensure we are always in a known state
_state = DialogResult.None;
// convert to nice wrapped lines.
text = AddNewLinesToText(text);
// get pixel width and height
Size textSize = TextRenderer.MeasureText(text, SystemFonts.DefaultFont);
// allow for icon
if (icon != MessageBoxIcon.None)
textSize.Width += SystemIcons.Question.Width;
var msgBoxFrm = new Form
{
FormBorderStyle = FormBorderStyle.FixedDialog,
ShowInTaskbar = true,
StartPosition = FormStartPosition.CenterParent,
Text = caption,
MaximizeBox = false,
MinimizeBox = false,
Width = textSize.Width + 50,
Height = textSize.Height + 120,
TopMost = true,
AutoScaleMode = AutoScaleMode.None,
};
Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
int titleHeight = screenRectangle.Top - msgBoxFrm.Top;
var lblMessage = new Label
{
Left = 58,
Top = 15,
Width = textSize.Width + 10,
Height = textSize.Height + 10,
Text = text
};
msgBoxFrm.Controls.Add(lblMessage);
msgBoxFrm.Width = lblMessage.Right + 50;
if (link != "" && linktext != "")
{
var linklbl = new LinkLabel { Left = lblMessage.Left, Top = lblMessage.Bottom, Width = lblMessage.Width, Height = 15, Text = linktext, Tag = link };
linklbl.Click += linklbl_Click;
msgBoxFrm.Controls.Add(linklbl);
}
var actualIcon = getMessageBoxIcon(icon);
if (actualIcon == null)
{
lblMessage.Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN);
}
else
{
var iconPbox = new PictureBox
{
Image = actualIcon.ToBitmap(),
Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN)
};
msgBoxFrm.Controls.Add(iconPbox);
}
AddButtonsToForm(msgBoxFrm, buttons);
// display even if theme fails
try
{
if (ApplyTheme != null)
ApplyTheme(msgBoxFrm);
//ThemeManager.ApplyThemeTo(msgBoxFrm);
}
catch { }
DialogResult test;
test = msgBoxFrm.ShowDialog();
//.........这里部分代码省略.........
示例7: NewWindowContentCloser
public NewWindowContentCloser(MgControlView control, Form owner)
{
_frm = new Form();
_control = control;
Rectangle screenRectangle = _frm.RectangleToScreen(_frm.ClientRectangle);
int titleHeight = screenRectangle.Top - _frm.Top;
_frm.Width = Math.Max(_control.Size.Width, _control.PreferredSize.Width);
_frm.Height = Math.Max(_control.Size.Height, _control.PreferredSize.Height) + titleHeight + 10; //HACK: height calculation is imperfect, so pad out
_frm.Text = _control.Title;
_frm.Controls.Add(_control);
_control.Closer = this;
if (control.ModalWindow)
_frm.ShowDialog(owner);
else
_frm.Show(owner);
}
示例8: Show
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
if (text == null)
text = "";
if (caption == null)
caption = "";
// ensure we are always in a known state
_state = DialogResult.None;
// convert to nice wrapped lines.
text = AddNewLinesToText(text);
// get pixel width and height
Size textSize = TextRenderer.MeasureText(text, SystemFonts.DefaultFont);
// allow for icon
if (icon != MessageBoxIcon.None)
textSize.Width += SystemIcons.Question.Width;
var msgBoxFrm = new Form
{
FormBorderStyle = FormBorderStyle.FixedDialog,
ShowInTaskbar = false,
StartPosition = FormStartPosition.CenterScreen,
Text = caption,
MaximizeBox = false,
MinimizeBox = false,
Width = textSize.Width + 50,
Height = textSize.Height + 100,
TopMost = true,
TopLevel = true,
};
Rectangle screenRectangle = msgBoxFrm.RectangleToScreen(msgBoxFrm.ClientRectangle);
int titleHeight = screenRectangle.Top - msgBoxFrm.Top;
var lblMessage = new Label
{
Left = 58,
Top = 15,
Width = textSize.Width + 10,
Height = textSize.Height + 10,
Text = text
};
msgBoxFrm.Controls.Add(lblMessage);
var actualIcon = getMessageBoxIcon(icon);
if (actualIcon == null)
{
lblMessage.Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN);
}
else
{
var iconPbox = new PictureBox
{
Image = actualIcon.ToBitmap(),
Location = new Point(FORM_X_MARGIN, FORM_Y_MARGIN)
};
msgBoxFrm.Controls.Add(iconPbox);
}
AddButtonsToForm(msgBoxFrm, buttons);
// display even if theme fails
try
{
ThemeManager.ApplyThemeTo(msgBoxFrm);
}
catch { }
if (System.Windows.Forms.Application.OpenForms.Count > 0)
{
msgBoxFrm.StartPosition = FormStartPosition.Manual;
Form parentForm = System.Windows.Forms.Application.OpenForms[0];
// center of first form
msgBoxFrm.Location = new Point(parentForm.Location.X + parentForm.Width / 2 - msgBoxFrm.Width / 2,
parentForm.Location.Y + parentForm.Height / 2 - msgBoxFrm.Height / 2);
DialogResult test = msgBoxFrm.ShowDialog();
}
else
{
DialogResult test = msgBoxFrm.ShowDialog();
}
DialogResult answer = _state;
return answer;
}
示例9: TestPublicMethods
public void TestPublicMethods ()
{
// Public Methods that force Handle creation:
// - CreateGraphics ()
// - GetChildAtPoint ()
// - Invoke, BeginInvoke throws InvalidOperationException if Handle has not been created
// - PointToClient ()
// - PointToScreen ()
// - RectangleToClient ()
// - RectangleToScreen ()
// - Select ()
// - Show (IWin32Window)
// Notes:
// - CreateControl does NOT force Handle creation!
Form c = new Form ();
c.BringToFront ();
Assert.IsFalse (c.IsHandleCreated, "A1");
c.Contains (new Form ());
Assert.IsFalse (c.IsHandleCreated, "A2");
c.CreateControl ();
Assert.IsFalse (c.IsHandleCreated, "A3");
c = new Form ();
Graphics g = c.CreateGraphics ();
g.Dispose ();
Assert.IsTrue (c.IsHandleCreated, "A4");
c.Dispose ();
c = new Form ();
c.Dispose ();
Assert.IsFalse (c.IsHandleCreated, "A5");
c = new Form ();
// This is weird, it causes a form to appear that won't go away until you move the mouse over it,
// but it doesn't create a handle??
//DragDropEffects d = c.DoDragDrop ("yo", DragDropEffects.None);
//Assert.IsFalse (c.IsHandleCreated, "A6");
//Assert.AreEqual (DragDropEffects.None, d, "A6b");
//Bitmap b = new Bitmap (100, 100);
//c.DrawToBitmap (b, new Rectangle (0, 0, 100, 100));
//Assert.IsFalse (c.IsHandleCreated, "A7");
//b.Dispose ();
c.FindForm ();
Assert.IsFalse (c.IsHandleCreated, "A8");
c.Focus ();
Assert.IsFalse (c.IsHandleCreated, "A9");
c.GetChildAtPoint (new Point (10, 10));
Assert.IsTrue (c.IsHandleCreated, "A10");
c.Dispose ();
c = new Form ();
c.GetContainerControl ();
Assert.IsFalse (c.IsHandleCreated, "A11");
c.Dispose ();
c = new Form ();
c.GetNextControl (new Control (), true);
Assert.IsFalse (c.IsHandleCreated, "A12");
c.GetPreferredSize (Size.Empty);
Assert.IsFalse (c.IsHandleCreated, "A13");
c.Hide ();
Assert.IsFalse (c.IsHandleCreated, "A14");
c.Invalidate ();
Assert.IsFalse (c.IsHandleCreated, "A15");
//c.Invoke (new InvokeDelegate (InvokeMethod));
//Assert.IsFalse (c.IsHandleCreated, "A16");
c.PerformLayout ();
Assert.IsFalse (c.IsHandleCreated, "A17");
c.PointToClient (new Point (100, 100));
Assert.IsTrue (c.IsHandleCreated, "A18");
c.Dispose ();
c = new Form ();
c.PointToScreen (new Point (100, 100));
Assert.IsTrue (c.IsHandleCreated, "A19");
c.Dispose ();
c = new Form ();
//c.PreProcessControlMessage ???
//c.PreProcessMessage ???
c.RectangleToClient (new Rectangle (0, 0, 100, 100));
Assert.IsTrue (c.IsHandleCreated, "A20");
c.Dispose ();
c = new Form ();
c.RectangleToScreen (new Rectangle (0, 0, 100, 100));
Assert.IsTrue (c.IsHandleCreated, "A21");
c.Dispose ();
c = new Form ();
c.Refresh ();
//.........这里部分代码省略.........
示例10: SnapToDesktopBorder
public void SnapToDesktopBorder(
Form theClientForm,
IntPtr LParam,
int theWidthAdjustment)
{
if (theClientForm == null)
{
throw new ArgumentNullException();
}
// Snap client to the top, left, bottom or right desktop border
// as the form is moved near that border.
try
{
// Marshal the LPARAM value which is a WINDOWPOS struct
WINDOWPOS theNewPosition = new WINDOWPOS();
theNewPosition = (WINDOWPOS)Marshal.PtrToStructure(
LParam, theNewPosition.GetType());
if (theNewPosition.y.Equals(0) || theNewPosition.x.Equals(0))
{
return;
}
// Adjust the client size for borders and caption bar
Rectangle theClientRectangle =
theClientForm.RectangleToScreen(theClientForm.ClientRectangle);
theClientRectangle.Width +=
SystemInformation.FrameBorderSize.Width - theWidthAdjustment;
theClientRectangle.Height +=
SystemInformation.FrameBorderSize.Height + SystemInformation.CaptionHeight;
// Now get the screen working area (without taskbar)
Rectangle theWorkingRectangle =
Screen.FromControl(theClientForm).WorkingArea;
// Left border
if (theNewPosition.x >= theWorkingRectangle.X - SNAP_OFFSET &&
theNewPosition.x <= theWorkingRectangle.X + SNAP_OFFSET)
{
theNewPosition.x = theWorkingRectangle.X;
}
// Get screen bounds and taskbar height (when taskbar is horizontal)
Rectangle theScreenRectangle =
Screen.FromControl(theClientForm).Bounds;
int theTaskBarHeight =
theScreenRectangle.Height = theWorkingRectangle.Height;
// Top border (check if taskbar is on top or bottom via WorkingRect.Y)
if (theNewPosition.y >= -SNAP_OFFSET &&
(theWorkingRectangle.Y > 0 && theNewPosition.y <= (theTaskBarHeight + SNAP_OFFSET)) ||
(theWorkingRectangle.Y <= 0 && theNewPosition.y <= SNAP_OFFSET))
{
if (theTaskBarHeight > 0)
{
theNewPosition.y = theWorkingRectangle.Y; // Horizontal Taskbar
}
else
{
theNewPosition.y = 0; // Vertical Taskbar
}
}
// Right border
if (theNewPosition.x + theClientRectangle.Width <= theWorkingRectangle.Right + SNAP_OFFSET &&
theNewPosition.x + theClientRectangle.Width >= theWorkingRectangle.Right - SNAP_OFFSET)
{
theNewPosition.x =
theWorkingRectangle.Right - (theClientRectangle.Width + SystemInformation.FrameBorderSize.Width);
}
// Bottom border
if (theNewPosition.y + theClientRectangle.Height <= theWorkingRectangle.Bottom + SNAP_OFFSET &&
theNewPosition.y + theClientRectangle.Height >= theWorkingRectangle.Bottom - SNAP_OFFSET)
{
theNewPosition.y =
theWorkingRectangle.Bottom - (theClientRectangle.Height + SystemInformation.FrameBorderSize.Height);
}
// Marshal it back
Marshal.StructureToPtr(theNewPosition, LParam, true);
}
catch
{
throw;
}
}
示例11: CapturarPantalla
/// <summary>
/// Draws the Form into a Bitmap.
/// </summary>
private void CapturarPantalla(Form frm)
{
bool oldTopMostState = frm.TopMost;
bool oldVisibleState = frm.Visible;
frm.Visible = true;
frm.TopMost = true;
Application.DoEvents();
Rectangle frmR = frm.ClientRectangle;
Rectangle srcR = frm.RectangleToScreen(frmR);
Graphics g = frm.CreateGraphics();
Size s = new Size(srcR.Width, srcR.Height);
imagen = new Bitmap(srcR.Width, srcR.Height, g);
Graphics g2 = Graphics.FromImage(imagen);
g2.CopyFromScreen(srcR.Location.X, srcR.Location.Y, 0, 0, s);
frm.TopMost = oldTopMostState;
frm.Visible = oldVisibleState;
}