VB.NET - how to set the z-level of the form in vb.net

Asked By abinav shankar on 17-Nov-11 04:35 AM


Have a form in which when i click a button i get another form which appears at the center of the screen now my requirement is when i click outside of the form i should get the parent form infront and this form should be at the back of the form what should i set in the form properties so that i can get this done

Reena Jain replied to abinav shankar on 17-Nov-11 04:48 AM

The Z-order of a control is determined by its index in the container's Controls collection.  The one at index 0 is on top, the last one is at the bottom.  One thing you can do is give all the labels you create the same Click event.  Then you can find the candidate labels with a Click event handler like this:    private void Label_Click(object sender, EventArgs e) {
    Label lbl = sender as Label;
    Point pos = lbl.Parent.PointToClient(Control.MousePosition);
    foreach (Control ctl in lbl.Parent.Controls) {
      if (ctl is Label && new Rectangle(ctl.Location, ctl.Size).Contains(pos))