展开全部
下面这个例子主要就是通过相对坐标获得父窗口中具体位置的坐标,然后将子窗口的Loaction设置为该坐标。具体情况可根据你的需求不同来计算这个Location。这样就可以达到弹出的窗口是在父窗口的左下角、右下角、左上角、右上角、中间等位置固定显示的效果。
/// <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
}
/// <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
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个我才做了
其实很简单 在子窗体的lord 事件里面写 location就OK
不要再父窗体里面设置~
看不明白给我留言
其实很简单 在子窗体的lord 事件里面写 location就OK
不要再父窗体里面设置~
看不明白给我留言
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
很简单啊,在子窗体的加载事件里面写参数就可以了!Location()
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询