|
-
Sep 3rd, 2006, 08:17 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Win32Exception
I have used this code in many of my applications but now it seems to be erroring and I'm not sure what is causing the error. Basically when I click on the NotifyIcon I want o show the form and when its minimized i want to not show up in the taskbar.
VB Code:
Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
If Me.WindowState = FormWindowState.Minimized Then
Me.ShowInTaskbar = False
NotifyIcon.Visible = True
Else
[COLOR=Red] Me.ShowInTaskbar = True 'Error[/COLOR]
NotifyIcon.Visible = False
End If
End Sub
Here is the execption that is getting thrown.
System.ComponentModel.Win32Exception was unhandled ErrorCode=-2147467259 Message="Error creating window handle." Source="System.Windows.Forms"
Any ideas for a solution?
Thanks In Advance
-
Sep 3rd, 2006, 08:31 PM
#2
Hyperactive Member
Re: [2005] Win32Exception
Instead of having a form that has the showInTaskbar property changed, consider having one form that always shows in the taskbar. Then when you click the NotifyIcon, open a new instance of that form, and when minimising, close the instance of that form. That may solve your problem.
-
Sep 3rd, 2006, 08:53 PM
#3
Re: [2005] Win32Exception
I disagree with ZaNi's solution. What you're doing is the appropriate way to do things. I can't tell you why you're getting that issue because I've done what you're doing many times before and it's been fine. Have you tried the same thing with a different form? Have you tried rebuilding (not just building) your project? How are you restoring the form? Are you using the DoubleClick event of the NotifyIcon something like this:
VB Code:
Private Sub NotifyIcon1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NotifyIcon.DoubleClick
Me.WindowState = FormWindowState.Normal
End Sub
Are you Closing the form before that point?
-
Sep 3rd, 2006, 08:59 PM
#4
Lively Member
Re: [2005] Win32Exception
how about
VB Code:
Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
If Me.WindowState = FormWindowState.Minimized Then
Me.ShowInTaskbar = False
NotifyIcon.Visible = True
Else
Me.Show()
WindowState = FormWindowState.Normal
End If
End Sub
-
Sep 3rd, 2006, 09:03 PM
#5
Re: [2005] Win32Exception
 Originally Posted by one_&_only
how about
VB Code:
Private Sub Main_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
If Me.WindowState = FormWindowState.Minimized Then
Me.ShowInTaskbar = False
NotifyIcon.Visible = True
Else
Me.Show()
WindowState = FormWindowState.Normal
End If
End Sub
The SizeChanged event is being handled. It's setting the WindowState to Normal that will raise the event, so setting the WindowState to Normal in the event handler isn't useful. Plus that doesn't change the task bar visibility of the form or the tray icon.
-
Sep 3rd, 2006, 09:06 PM
#6
Thread Starter
Fanatic Member
Re: [2005] Win32Exception
I have tried rebuilding and tried it on a different project and works fine. I am triggering the event by using the click event.
VB Code:
Private Sub NotifyIcon_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon.MouseClick
If e.Button = Windows.Forms.MouseButtons.Left Then
Me.WindowState = FormWindowState.Normal
End If
End Sub
-
Sep 3rd, 2006, 10:11 PM
#7
Thread Starter
Fanatic Member
Re: [2005] Win32Exception
I seems I have fixed this problem by removing a minimize on lostfocus event within a textbox.
-
Sep 3rd, 2006, 10:13 PM
#8
Re: [RESOLVED] [2005] Win32Exception
As the documentation says, don't use the GotFocus or LostFocus events except under the very specific circumstances that it mentions. Use Enter and Leave for most controls and Activated and Deactivate for forms.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|