Showing a child form that "isn't" blank within an MDI

MikeyLDS

Freshman
Joined
Aug 25, 2004
Messages
35
Hiya guys ... met me appologise in advance. I have searched the forums but my question doesn't appear to be answered.

When I try to display a form within another I never seems to show.

Also when I try to show a form as a dialogue it just shows a new blank form.

Here is some of my code:

Code:
    Private Sub mnuOptions_Select(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuOptions.Select
        'Show "frmOptions" form so that user must close before continuing on main form
        Dim dlgOptions As New Form
        dlgOptions.ShowDialog()
    End Sub

When I run this it just shows a blank dialog form. I get the same problem trying to show a child within an MDI.

Any suggestions?
 
Assuming dlgOptions is the actual form, you just need to create an instance of it:

Visual Basic:
Dim dlgOptions As new dlgOptions 
dlgOptions.ShowDialog()
 
It really depends what the form name is, and what you want to call your variable:

Dim VARIABLENAME As New THEFORMNAME
VARIABLENAME.ShowDialog()
 
Didin't mean to sound rude stustarz but he did mention what his form name was in his comment in the code.
 
ahhhhhh ;) didnt see that!!! he he

maybe thats why it can take me days to debug simple stuff sometimes! :D
 
stustarz said:
It really depends what the form name is, and what you want to call your variable:

Dim VARIABLENAME As New THEFORMNAME
VARIABLENAME.ShowDialog()

Hey that was very handy! Many thanks guys ... I am now a little confused though. I have about 7 forms and only one of them seems to work (in the context sensitive thingie) :confused:

Should these forms be referenced in some other part of my code somehow?
 
Do you mean: in the intellisense dropdown list you can only see one of your forms? :)

If that is the case, maybe you have changed the name of your form, and not changed the actual class name for the form? If you open your form in code view, check the first line (after any import statements if you have any): Public Class CLASSNAME - this classname will be what is displayed in intellisense (if it is public of course!)
 
stustarz said:
Do you mean: in the intellisense dropdown list you can only see one of your forms? :)

If that is the case, maybe you have changed the name of your form, and not changed the actual class name for the form? If you open your form in code view, check the first line (after any import statements if you have any): Public Class CLASSNAME - this classname will be what is displayed in intellisense (if it is public of course!)

Wonderful ... that works and makes much more sense than other peeps had mentioned ;)
 
Code:
Private Sub btnShowClientDetails_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShowClientDetails.Click
        Dim ShowForm As New frmClientDetails
        ShowForm.Show()
    End Sub

One last thing ... The .showdialog works ok now but for some reason a different form won't show within my mdi container. The name of the form is recognised but simply shows on top of the current MDI as a stand alone window.
 
Well, this is the way i do it! :) .

Firstly create a public variable in the Main MDI Parent form: Directly after the "Windows Form Designer Generated Code" region add the line:

Visual Basic:
Public Shared frmParentForm As System.Windows.Forms.Form

In the main mdi parent forms load event add:

Visual Basic:
frmParentForm = Me

Now each time you need to open an mdi child use the following code:

Visual Basic:
        Dim ShowForm As New frmClientDetails
        'This is the line you need to add:
        ShowForm.MDIParent = frmParentForm
        ShowForm.Show()
 
One last thing stustarz ... how come your code clearly shows as "VB Code" and on a white background with the blue and green colours? :o

By the way ... it worked well (again) ... I should add you as a buddy ... which messenger do you use?
 
Just change the word "code" to "vb" on the tags around the code you want to display :)

I use MSN at work, i'll add you when im next on it
 
Back
Top