Hi all,

I am new to C#,i just need your help in figuring out the issues.


I have two windows forms :"background form " and "foreground form".

1)minimise the background form when foreground form is minimised.
2)move the "background form" when "foreground form is moved"

Please tell me how to do this.

Thanks in advance.


Regards,
Shelly.

Create an instance of the background form from inside your foreground form and display it using .Show(). Then, handle the LocationChanged event of your foreground form and set the background form's Location relative to your foreground form's Location. As the background form was created from inside the foreground, it will minimise whenever its parent form (the foreground form) does.

@yamachi:
Thanks for ur reply.

But,
In foregroundform load i have the code like this:

private void foregroundform_Load(object sender, EventArgs e)
{
backgroundform obj=new backgroundform();
obj.show();

}

if i minimise the foreground form, background form is not getting minimised.

please help me to solve this.

Thanks for ur reply.

But,
In foregroundform load i have the code like this:

private void foregroundform_Load(object sender, EventArgs e)
{
backgroundform obj=new backgroundform();
obj.show();

}

if i minimise the foreground form, background formis not getting minimised.

please help me to solve this.

Create an instance of the background form from inside your foreground form and display it using .Show(). Then, handle the LocationChanged event of your foreground form and set the background form's Location relative to your foreground form's Location. As the background form was created from inside the foreground, it will minimise whenever its parent form (the foreground form) does.

hmm, that's odd as it works fine for me. Anyways, you can see if the form was minimised by handling the foreground form's Resize event and checking its window state:

// Handles the foregroundForm.Resize event
private void foregroundForm_Resize(object sender, EventArgs e)
{
    if (this.WindowState == FormWindowState.Minimized)
        backgroundForm.WindowState = FormWindowState.Minimized;
}

Edited 6 Years Ago by Yamachi: n/a

Try passing the foreground form to the show method of the background form.

backgroundform obj=new backgroundform();
obj.show(this)

This makes the background form a child of the foreground form and should now minimise with the foreground form.

@ yamachi and nick.crane thank you for the reply.:-)

It is working fine now..(previously --background form wasn't minimising due to a logical error. now, fixed it).

thanks a lot.

Regards,
Shelly.

This question has already been answered. Start a new discussion instead.