您的位置:首页 > 编程语言

在当前按钮位置弹出窗体的代码。自动计算弹出方位。

2009-07-23 09:29 483 查看
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();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐