Error creating window handle

  • Thread starter Thread starter George Waters
  • Start date Start date
G

George Waters

Guest
Hi,

I have a MDI container and also I use my own custom class MsgBox called ShowMsg which I use mostly on the child forms, so far it worked fine until I realized that the Showmsg did not stick to the parent form (MDIContainer), since my Showmsg class uses a showdialog() but the class cannot see the MDIContainer, I created a global var type Windows.Forms.Form and assign it the MDIContainer, now in my Showmsg class I can use ShowDialog(MDIvar) to let it know who is the parent.

Now, sometimes I get the error "Error creating window handle" which I don't know why this happens.

This is part of the code:

Public Function ShowMsg(ByVal Text As String, ByVal Icon As ShowMsgImage, ByVal Title As String) As DialogResult
Dim SMF As New ShowMsgForm

'Set the title bar
SMF.Text = Title

'Select an image and sound based on the Icon parameter
Select Case Icon
Case ShowMsgImage.Alert
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Warning
SMF.Sound = Media.SystemSounds.Asterisk
Case ShowMsgImage.Confirm
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Confirm
SMF.Sound = Media.SystemSounds.Question
Case ShowMsgImage.Critical
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_NotAllowed
SMF.Sound = Media.SystemSounds.Hand
Case ShowMsgImage.Info
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Info
SMF.Sound = Media.SystemSounds.Asterisk
Case ShowMsgImage.Security
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_Lock
SMF.Sound = Media.SystemSounds.Beep
Case ShowMsgImage.UnderConstruction
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_NotAllowed
SMF.Sound = Media.SystemSounds.Asterisk
Case ShowMsgImage.Ok
SMF.MessagePictureBox.Image = My.Resources.ico_showmsg_ok
SMF.Sound = Media.SystemSounds.Asterisk
End Select

'Set other properties
SMF.TextLabel.Text = Text
SMF.QuestionTextLabel.Text = ""
SMF.Button1.Visible = True
SMF.Button1.Text = "OK"
SMF.Button1.DialogResult = DialogResult.OK
SMF.Button2.Visible = False
SMF.Button3.Visible = False

'Resize the form
SMF.SizeForm()

'Set its starting position
SMF.StartPosition = FormStartPosition.CenterScreen

'Display the form modally and return its DialogResult
Try
Return SMF.ShowDialog(MFR)
Catch ex As Exception

End Try


End Function


Any ideas what could be wrong?


Regards.


G.Waters

Continue reading...
 
Back
Top