最大坐标值应该是int类型的值域最大值。但是坐标值只有在显示器的分辨率范围内时,我们才能在显示器上看到窗口,例如显示器分辨率为800*600
那么:当窗口的坐标值不在这个范围内,我们就不能看到窗口,或只能看到部分窗口。
下面这个例子主要就是通过相对坐标获得父窗口中具体位置的坐标,然后将子窗口的Loaction设置为该坐标。具体情况可根据你的需求不同来计算这个Location。这样就可以达到d出的窗口是在父窗口的左下角、右下角、左上角、右上角、中间等位置固定显示的效果。/// <summary>
/// 设置提示窗口的显示位置
/// </summary>
/// <param name="parentForm">父类窗体</param>
private void SetFormShowPosition(Form parentForm)
{
if (m_IsUserSize == false)
{
// m_FormShowLocation为窗口显示模式,在下面有该枚举的定义。
if (m_FormShowLocation == FormShowMode.LeftBottom || m_FormShowLocation == FormShowMode.RightBottom)
{
this.Size = new Size(180, 129)
}
else
{
this.Size = new Size(280, 129)
}
}
Point showPoint = Point.Empty
int parentFormWidth = parentForm.Size.Width
int parentFormHeight = parentForm.Size.Height
int hitWidth = this.Width
int hitHeight = this.Height
if (m_FormShowLocation == FormShowMode.RightBottom || m_FormShowLocation == FormShowMode.RightBottomBig)
{
showPoint = new Point(parentFormWidth - hitWidth -18, parentFormHeight - hitHeight - System.Windows.Forms.SystemInformation.CaptionHeight - 26)
if (m_IsKeepSize)
{
showPoint = new Point(showPoint.X + 14, showPoint.Y + 21)
}
}
else if (m_FormShowLocation == FormShowMode.LeftBottom || m_FormShowLocation == FormShowMode.LeftBottomBig)
{
showPoint = new Point(9, parentFormHeight - hitHeight - System.Windows.Forms.SystemInformation.CaptionHeight - 9)
}
else if (m_FormShowLocation == FormShowMode.MiddleCenterBig)
{
showPoint = new Point((parentFormWidth - hitWidth) / 2,
(parentFormHeight - hitHeight) / 2 - System.Windows.Forms.SystemInformation.CaptionHeight - 9)
}
this.Location = parentForm.PointToScreen(showPoint)
this.Opacity = 0
if (this.Visible == false)
this.Show(parentForm)
else
this.Opacity = 1
}
/// <summary>
/// 窗体显示模式
/// </summary>
public enum FormShowMode
{
/// <summary>
/// 标准大小,左下角
/// </summary>
LeftBottom,
/// <summary>
/// 标准大小,右下角
/// </summary>
RightBottom,
/// <summary>
/// 大窗体,左下角
/// </summary>
LeftBottomBig,
/// <summary>
/// 大窗体,右下角
/// </summary>
RightBottomBig,
/// <summary>
/// 大窗体,居中
/// </summary>
MiddleCenterBig
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)