private void button_Click(object sender, System.EventArgs e)
{
string data = "data"
Form f = new Form();
try
{
int topx = this.Parent.PointToScreen(this.Location).X;
int topy = this.Parent.PointToScreen(this.Location).Y;
int bottomx = topx + this.Width;
int bottomy = topy + this.Height;
if (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width - topx >= f.Width)
f.Left = topx;
else
f.Left = bottomx - f.Width;
if (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height - bottomy >= f.Height)
f.Top = bottomy;
else
f.Top = topy - f.Height;
f.Data = data;
if (f.ShowDialog() == System.Windows.Forms.DialogResult.Yes)
{
}
}
catch (Exception ex)
{
throw new Exception(this.Name,ex);
}
finally
{
f.Dispose();
}
}
在当前按钮位置弹出窗体的代码。自动计算弹出方位。
窗体位置计算与数据传递
最新推荐文章于 2020-12-29 07:59:53 发布
本文介绍了一个关于窗体位置计算的示例代码,该代码通过计算当前窗体的位置来决定新弹出窗体的位置,并实现了数据在不同窗体间的传递。此外,还包含了异常处理和资源释放的相关实现。
1428

被折叠的 条评论
为什么被折叠?



