Error creating window handle RRS feed

  • Question

  • 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
            'Set its starting position
            SMF.StartPosition = FormStartPosition.CenterScreen
            'Display the form modally and return its DialogResult
                Return SMF.ShowDialog(MFR)
            Catch ex As Exception
            End Try
        End Function

    Any ideas what could be wrong?



    Thursday, January 24, 2019 5:44 PM

All replies

  • Hi,

    see the following link:


    Best Regards,


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 25, 2019 6:36 AM