Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two win form's,i have minimized 2nd win form using

C#
this.WindowState = FormWindowState.Minimized
this.ShowInTaskbar = true;
and i have timer in 1st winform which is set to fire for every 17s and when next cycle of timer hits the event in 1st winform i am trying to obtain 2nd win-form window state using
C#
frmPopup objPopup = new frmPopup(false);
MessageBox.Show(""+objPopup.WindowState+"");



Form_2_Code:

C#
 private void Form2_SizeChanged(object sender, EventArgs e)
    {
        if (WindowState == FormWindowState.Minimized)
        {
            isMinimized = 1;
        }
    }
private void Minimize_Click(object sender, EventArgs e)
    {
            this.Resize -= new EventHandler(Form2_SizeChanged);
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.WindowState = FormWindowState.Minimized;
            this.ShowInTaskbar = true;
            this.Resize += new EventHandler(Form2_SizeChanged);
   }

  private void btnOK_Click(object sender, EventArgs e)
    {
        Process[] processes = Process.GetProcessesByName("XXXX");
        if (processes.Length != 0)
        {
            lblWarning.Visible = true;
        }
        else
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
        this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    }

Form_1_code :

frmPopup objPopup = new frmPopup(false); // global declaration

C#
       private void timer3_Tick(object sender, EventArgs e)
       {
          Process[] process1 = Process.GetProcessesByName("XXXX");
          int iWindowstate = objPopup.isMinimized; // objPopup is object for Form2 which is declared as global in Form1
           if ((iWindowstate == 0 && process1.Length == 0) || (iWindowstate == 1 && process1.Length == 0))
           {
            if (objPopup.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
               //dialog.Result.ok
             }
          }
timer3.Enabled = true;
       }


My Question : if i minimize 2nd winform i need to be placed in taskbar eventhough i can able to get windowstate of 2nd winform i need to 2nd winform to be placed in taskbar not in systemsTray in minimized state but its disappears
Posted
Updated 4-Jan-15 23:21pm
v7

1 solution

Form2's Minimize_Click() method sets its DialogResult value. According to the "Remarks" section in the link, doing so hides forms that have been shown using the ShowDialog method.

However, the hidden form should still be accessible if there is a reference to it.

[Edit]
Set a breakpoint onto the first line of code in Form1's Timer.Tick event handler.
Does it really not get called or does it, but doesn't perform the action you expect?
If it doesn't get called: Is there some code like
C#
timer3.Tick -= WhateverMethod;  // or
timer3.Stop();                  // or
timer3.Enabled = false;         // or
timer3 = new Timer();           // other than the initialization
The first one unsubscribes your method from the event so it doesn't get called.
Lines 2 and 3 disable the timer altogether. So the event doesn't even fire.
Line 4 would set the 'timer3' reference to a new Timer object. Even though that should not intervene with the old object firing its event, it would be a "code smell" in my eyes (or nose) to inspect in more detail.
[/Edit]
 
Share this answer
 
v2
Comments
pradeepbliss 5-Jan-15 5:15am    
if i didn't return dialog result,i can able to see form2 in taskbar but timer is not hitting its next 17s cycle..
lukeer 7-Jan-15 5:31am    
I updated my solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900