-
Apr 8th, 2014, 06:41 AM
#1
Thread Starter
Member
Error creating window handle
I'm having a problem with "Showing" one particular form.
I have a dozen forms all are children of an MDI form.
One particular form always fails on the first "Show" with the error "Error creating window handle", then the second time I load it, the "Show" succeeds.
I'm first attaching all the forms to the MDI form
Code:
frmAdmin.MdiParent = Me
frmAdmin.Dock = DockStyle.Fill
frmAdmin.Hide()
Then when the time comes to Show the form, I call a Subroutine to do the job:
Code:
Public Sub LoadFormAndRefresh(ByRef vForm As Form)
Const C_PROC_NAME = "LoadFormAndRefresh"
Try
' hide everything
For Each oForm As Form In Me.MdiChildren
oForm.Hide()
Next
Me.Refresh()
vForm.Show() <------------------- fails here
Me.Refresh()
Catch ex As Exception
If modGlobals.gDebug Then Console.Write(CODE_MODULE, C_PROC_NAME & ": " & ex.Message)
oERR.LogFileError(vModule:=CODE_MODULE,
vRoutine:=C_PROC_NAME,
vEX:=ex,
vLogLevel:=clsLogFile.LoggingLevel.LogEverything)
If modGlobals.gDebug Then Stop
End Try
End Sub
The code steps through the frmAdmin_Load subroutine with no errors then fails when back in the MDI routine.
Any ideas?
-
Apr 8th, 2014, 07:20 AM
#2
Re: Error creating window handle
Have a look at the StackTrace of the exception. It will tell you where the actual error occurs. Almost certainly it's in an event handler that is executed due to a property that you have set in the designer. For example, if you have set the Text of a TextBox then the TextChanged event will be raised and the event handler might assume that something has happened that hasn't at that stage.
-
Apr 8th, 2014, 07:49 AM
#3
Thread Starter
Member
Re: Error creating window handle
These are the Exception details for the error
Code:
Exception Details:
HResult: -2147467259
Message: Error creating window handle.
String: System.ComponentModel.Win32Exception (0x80004005): Error creating window handle.
at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at WindowsApplication1.mdiMain.LoadFormAndRefresh(Form& vForm) in C:\Users\usr\Documents\Visual Studio 2012\Projects\WindowsApplication1\WindowsApplication1\mdiMain.vb:line 189
Source: System.Windows.Forms
-
Apr 8th, 2014, 11:03 AM
#4
Re: Error creating window handle
are you using the default instance of the form?
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Apr 8th, 2014, 05:34 PM
#5
Re: Error creating window handle
Oh man oh man. I think MDIs are glitched in .Net. You wouldn't believe the amount of weird and unexplainable problems like this I've come across when using them. It might be something you're doing wrong but my experience tells me its more than likely another glitch. You should try to find out what conditions cause the error(bet my left foot it'll be weird conditions too) and work around them.
-
Apr 8th, 2014, 05:36 PM
#6
Re: Error creating window handle
Hmmm... is there an InnerException?
-
Apr 9th, 2014, 04:51 AM
#7
Thread Starter
Member
Re: Error creating window handle
I couldn't find an InnerException, but the following (very dirty) bit of code works...
Code:
Try
frmAdmin.Show()
Catch ex As Exception
frmAdmin.Show()
End Try
The first attempt always fails then the second attempt always seems to work.
-
Apr 9th, 2014, 12:28 PM
#8
Re: Error creating window handle
Try creating a new instance (do that always)
Code:
Using newForm as New frmAdmin
newForm.Show()
End Using
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
-
Apr 10th, 2014, 04:08 AM
#9
Thread Starter
Member
Re: Error creating window handle
That new form business just make things worse. Nothing was loaded, all the forms load then vanish leaving an empty MDI container. The way I had it was better, even with the dirty workaround.
-
Apr 10th, 2014, 08:14 AM
#10
Re: Error creating window handle
ok, do without the Using -End Using, but do not use the default instance.
More important than the will to succeed, is the will to prepare for success.
Please rate the posts, your comments are the fuel to keep helping people
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
|