how to keep a form on top of another
Say I have 3 forms , Form A , Form B , Form C.
I want Form B to be on top of Form A
开发者_如何学编程and Form C to be on top of Form B.
how do I accomplish this ?
When you call ShowDialog
pass the form that you want it to be in front of as a parameter to ShowDialog
.
Use the Show(owner) overload to get form B on top of A. You'll need to set the size and location in the Load event so you can be sure it is exactly the right size even after scaling. And listen for the LocationChanged event so you can move the bottom form as well. This works well, other than a few interesting minimizing effects on Win7.
private void button1_Click(object sender, EventArgs e) {
var frmB = new Form2();
frmB.StartPosition = FormStartPosition.Manual;
frmB.Load += delegate {
frmB.Location = this.Location;
frmB.Size = this.Size;
};
frmB.LocationChanged += delegate {
this.Location = frmB.Location;
};
frmB.Show(this);
}
精彩评论