Results 1 to 1 of 1

Thread: MDI: Argument Exception

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2005
    Location
    Debug.Print
    Posts
    3,885

    MDI: Argument Exception

    Hi, all,

    I am now trying to get used to Visual Studio 2010 Pro and I am trying to do something here. I am trying to centralize all my forms properties in the MDI application I have just started. The properties will be in a Public Sub within a module and then called in all the forms load event. I have two forms. MainForm which is going to be an MdiParent and LogonForm which is going to be an MdiChild. In the MdiParent, I have the following, I also have the same in the MdiChild load event:
    Code:
    Public Class MainForm
        Private Sub MainForm_Load(sender As Object, e As System.EventArgs) Handles Me.Load
            'Format the forms in the solution.
            'Module: AppWide.
            FormFormat(Me)
        End Sub
    End Class
    Then in the module, I have the following:
    Code:
    Module AppWide
        Public Sub FormFormat(ByRef Frm As Form)
            'This is a public sub that will span every form in the project solution.
            'The purpose of this public sub is to centralize the properties to be used for every form in the project solution.
    
            With Frm
                'The following properties will be used on all forms, regardless of purpose.
                .FormBorderStyle = FormBorderStyle.FixedToolWindow
                .KeyPreview = True
                .MinimizeBox = True
                .SizeGripStyle = False
    
                'The following will be used on all forms with slight variations depending on the forms name.
                Select Case Frm.Name
                    Case Is = "MainForm"
                        'The following will only be used if the name of the form is MainForm.
                        .StartPosition = FormStartPosition.CenterScreen
                        .IsMdiContainer = True
                        .MaximizeBox = False
                        .MinimizeBox = True
                    Case Else
                        'The following will be used if the forms name is not MainForm.
                        .StartPosition = FormStartPosition.CenterParent
                        .IsMdiContainer = False
                        .MaximizeBox = True
                        .MinimizeBox = True
                        .MdiParent = DirectCast(MainForm, Form)
                        .Show()
                End Select
            End With
        End Sub
    End Module
    When I launch the application (MainForm) is the first form in the startup. I get the following issue on the following line:
    Code:
    .MdiParent = DirectCast(MainForm, Form)
    Form that was specified to be the MdiParent for this form is not an MdiContainer.
    .MdiParent = Nothing
    Argument Exception was unhandled
    MainForm loads up and it looks like an MdiContainer but the second form doesn't load at all. Any ideas? I am not sure what is going on here but I would have thought that the .IsMdiContainer would have already been set to true on form load but it seems it isn't being set to true. The MdiChild form doesn't even show.

    Thanks in advance for any suggestions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width