Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Ok, I have the following code:

 

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       If Me.WindowState.Minimized = FormWindowState.Minimized Then
           Me.Hide()
       Else
           Exit Sub
       End If
   End Sub

   Private Sub cntShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntShow.Click
       Me.Show()
   End Sub

 

When I hit the minimize button it works like a charm. The Form hides itself and I am left with the Notify Icon. I have the cntShow_Click as a context menu item on the notify Icon. When I click it, the form does not show it self on screen. If I look in the task bar, I see that the form has been unhidden, but when I click on it, it hides itself again. When I click on the context menu again, the form shows up like I wanted it to in the first place.

 

Is there a check I am not doing that would fix this? Thanks for any help.

"Nobody knows what I do until I stop doing it."
Posted

Change your code to:

 

   Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       If Me.WindowState = FormWindowState.Minimized Then
           Me.Hide()
       End If
   End Sub

   Private Sub cntShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntShow.Click
       Me.Show()
       Me.WindowState = FormWindowState.Normal
   End Sub

TT

(*_*)

 

There are 10 types of people in this world;

those that understand binary and those that don't.

  • *Experts*
Posted
If Me.WindowState.Minimized = FormWindowState.Minimized Then

That needs to be

If Me.WindowState = FormWindowState.Minimized Then

Posted

I will try what you suggested. I got it to work this way as well, but your code looks a lot cleaner.

 

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       If Me.WindowState.Minimized = 1 And blnHide = False Then
           Me.Hide()
       Else
           blnHide = False
       End If
   End Sub

   Private Sub cntShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntShow.Click
       Me.Show()
       blnHide = True
       Me.WindowState = FormWindowState.Normal
   End Sub

 

blnhide is a form level var.

"Nobody knows what I do until I stop doing it."
Posted

OK, using VolteFace's suggestion, the new code is this:

 

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       If Me.WindowState = FormWindowState.Minimized Then
           Me.Hide()
       End If
   End Sub

   Private Sub cntShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntShow.Click
       Me.Show()
       Me.WindowState = FormWindowState.Normal
   End Sub

"Nobody knows what I do until I stop doing it."
  • *Experts*
Posted

Your code is still flawed;

 

If Me.WindowState.Minimized = 1 Then

Me.WindowState is the actual property you have to check. Me.WindowState.Minimized is a constant - if you check the value of that it will always remain the same.

Posted

The last code I posted removed the

If Me.WindowState.Minimized = 1 Then

 

Does the last code look fine?

 

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
       If Me.WindowState = FormWindowState.Minimized Then
           Me.Hide()
       End If
   End Sub

   Private Sub cntShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cntShow.Click
       Me.Show()
       Me.WindowState = FormWindowState.Normal
   End Sub

"Nobody knows what I do until I stop doing it."

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...