要求如下:
1 在当前窗体上的指定Button的Click事件弹出新的窗体
2 新弹出窗体初始位置的左边与Button左边对齐,新窗体下边在Button的上边/下边
子窗体代码:
public partial class frmSub : Form
{
public frmSub()
{
InitializeComponent();
}
public void SetPos(Point p)
{
StartPosition = FormStartPosition.Manual;//只有这样,以后的设置才生效
Rectangle disk = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
this.Location = p;
}
}
调用子窗体代码:
frmSub frm=new frmSub() ;
Point pos = this.btnCancel.PointToScreen(btnCancel.Location);
pos.X -= btnCancel.Location.X;
if ((this.Height - btnCancel.Location.Y- btnCancel.Height) >= frm.Height )
{
pos.Y = pos.Y - btnCancel.Location.Y + btnCancel.Height;
}
else
{
pos.Y = (pos.Y - btnCancel.Location.Y + btnCancel.Height) - btnCancel.Height - frm.Height ;
}
frm.SetPos(pos);
frm.Show(this);