I have 2 forms.
Form2 has no minimum, max, close icons.
Form2 have to control by form1.

i.e minimize of form1 becomes form2 minimize.
normal of form1 becomes form2 normal.
closing of form1 becomes form2 close.

All these are working.

but when form1 is behind the screen, i.e if form1 activates, form2 have to come front.

I have wrote activate event for this.
In this i have problem, if we use form activate event, when we click for minimize of form1, it calls form1 activate event and activates form2, but not minimize. It will go to infinite.

How to activate form2 when form1 activates, but when we minimize form1, form2 also have to minimize.

Form2= _rptForm

protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x0112) // WM_SYSCOMMAND
            {
                if (m.WParam == new IntPtr(0xF020)) //SC_MINIMUM
                {
                    _rptForm.WindowState = FormWindowState.Minimized;
                }

                if (m.WParam == new IntPtr(0xF120))       //SC_RESTORE
                {
                    _rptForm.WindowState = FormWindowState.Normal;
                }
               
                m.Result = new IntPtr(0);
            }
            base.WndProc(ref m);
        }

        private void DataBoxDlg_Activated(object sender, EventArgs e)
        {

            _rptForm.Activate();
        }

Please change this code to work all which i mention above.

Can i maybe give you a new approach ???

Ive done this like this

in the formload of form1

this.Tag = form2;

now you can access form 2, so now you can say on a button -

Form2.Show(); // If you want both to be active for use
Form2.ShowDialog(); // If you want form1 to be disabled

Now you can also say this on a button on form1

form2.close(); // If you want to close it
form2.WindowState = FormWindowState.Minimized;

Happy coding my friend ...

commented: nice +4

Indead cVz, if you can do it the easy way, why do it the hard way.

i dont have problem in minimizing,maximizing, Show and close. How to bring to front of the form2 when form1 activates.

I want only one operation.

When form1 is in normal state but behind another window, if we click that form1, form2 also have to come front along form1.


How to do this? Is it possible using tag itself. I dont have any buttons in the form.Please give me the solution for this.


Which event i have to call when form1 came front.

I want to do every operation of form1 reflects on form2.

minimize , maximize, normal, BringToFront, close etc...

All are working except Bring2Front.
Please suggest me the solution in simple way.

A Form has a TopMost property. I did not try it but if it is set to true the form shows above all other forms.

But i want event, when form1 come to front, to make form2 as topmost.

Need Event of form1, to make form2 as topMost.
when form1 come front from back screen.

Just minimize and maximize the form you want on top ...l it will work ...

@cVz:
I didnt get you, will u please explain in brief.

Just minimize and maximize the form you want on top ...l it will work ...

I want form2 should be in top, when form1 is also in top of other windows. To do this which event i have to call??

i.e if i click form1, both forms have to appear if it is behind the other windows.

You have your form declaration here

Form2 F2 = new Form2();
            F2.Show();
            F2.WindowState = FormWindowState.Minimized;

then you have this on the FormWindows State changed or on a button click

if (this.WindowState == FormWindowState.Normal)
            {
                F2.WindowState = FormWindowState.Normal;
            }

Hope it helps , mark as solved if it did... viola

I have mentioned so many times, minimize and maximize is not a aproblem for me.

I already wrote this code for minimize and maximize of both forms and working fine, but the problem is as follows.

Form1 and form2 both in normal mode.
if i click on 3rd window, both form1 and form2 will go behind that 3rd window.

Again if i want to see form1 and form2, i have to click on form1, so that both forms have to come front of third window and have to visible of both form1 and form2.

I hope u understood my question.

So do you want them to ALWAYS be on top ?? kind of like Windows live ?? or do you want them both to show if you click on form1 ?

There is an event like Activated. You can try that event.

    private void Form1_Activated(object sender, EventArgs e)
    {
        //code
    }

Dude this works

private void Form1_Activated(object sender, EventArgs e)
        {
            Form2 F2 = new Form2();

            F2.ShowDialog(); // Puts it on top (form1 wont be accessible)
            F2.Show();  // Makes form 1 accessible
        }

Hope that helps

Hold on ... not yet ... i will be with you now

if we use activate event, it will go infinite. not able to minimize of form1 or close of form1.

i had that same problem and that made me very crazy when i select any window and select my form the another form kept back to that window but i sort that out ;)


here is the code, mark this thread Solved

bool IsJustActivated = false;
        private void Xform_Activated(object sender, EventArgs e)
        {
            if (!IsJustActivated)
            {
                IsJustActivated = true;
                BackForm.Activate();
                bool tmp_holdValue = this.TopMost;
                this.TopMost = true;
                this.TopMost = tmp_holdValue; //this.Activate() wont work
            }
            else
                IsJustActivated = false;
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.