0

I don't want to see the new form. I need him to be maximized and same size as form1 but not to see it. So when i move/drag form1 around with the mouse i need that the new form behind it will be move/drag with form1.

This is a button click event in form1 that show the new form:

private void BeginOperationBut_Click(object sender, EventArgs e)
        {
            if (this.imageList.Count == 0)
            {
                wbss = new WebBrowserScreenshots();
                wbss.Show();
            }
        }

wbss is the new form.

I tried in the new form designer to set the property Locked to True but it didn't change anything.

What i want to do is two things:

  1. The new form should be show/start behind form1.
  2. The new form should be locked so when i drag/move around the form it will move the new form also. So i will not see the new form only form1.

The way it is now when i click the button the new form is showing over in front of form1.

Simon Gamlieli
  • 119
  • 1
  • 18

1 Answers1

1

There are a lot of things that need to be taken into consideration to make sure that this works as intended. Here is a snippet of code you can use to get started:

public partial class FollowForm : Form {

    readonly Form _master;

    private FollowForm() {
        InitializeComponent();
    }

    public FollowForm(Form master) {
        if (master == null)
            throw new ArgumentNullException("master");
        _master = master;
        _master.LocationChanged += (s, e) => Location = _master.Location;
        _master.SizeChanged += (s, e) => Size = _master.Size;
        ShowInTaskbar = false;
    }

    protected override void OnShown(EventArgs e) {
        base.OnShown(e);
        Location = _master.Location;
        Size = _master.Size;
        _master.Activate();
    }

    protected override void OnActivated(EventArgs e) {
        _master.Activate();
    }
}

I tried experimenting with the ShowWithoutActivation property, but the results were not as I expected.

The main aspects are tracking the change of size or location of the master form, and updating the follower form's size and location accordingly. Also, to send the follower form to the back when shown and re-activating the master form. Give it a try. This is from a .NET4.0 project, VS2013.

Usage

public partial class MasterForm : Form {

    FollowForm _follower;

    public MasterForm() {
        InitializeComponent();
    }

    private void button1_Click(object sender, EventArgs e) {
        _follower = new FollowForm(this);
        _follower.Show();
    }
}

For a better approach to the no-activate feature, take a look at:

Community
  • 1
  • 1
Leandro
  • 1,560
  • 17
  • 35