VB.NET Mdi project problem

H.w.Hendrick

New member
Joined
Oct 10, 2005
Messages
3
Programming Experience
Beginner
VB.NET Mdi project problem
--------------------------------------------------------------------------------
Hey,
I have a simple VB.NET Mdi project problem.
I have two Forms One Parent and One Child.
If i click on the button Open_Mdi_Child, the button disabled, the Child_Form shows and the Text Child_Form wil be appear.
But if i answered on de the Button_Answer in the Childform to the Parent form i see nothing changed in then Statusbox Text and it wil also not reset the show Child button.

Question: What i'm doing wrong and ho has the correct answer please.
Yours sincerelly
H.w. Hendrick

VB.NET:
Public Class Form1
Inherits System.Windows.Forms.Form
Shared Frm_Child As New Form2
#Region " Windows Form Designer generated code "
#End Region
Private Sub Open_Mdi_Child_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Open_Mdi_Child.Click
Open_Mdi_Child.Enabled = False
Frm_Child.MdiParent = Me
Frm_Child.Show()
Frm_Child.TextBox_Mdi_Child.Text = "Nano Nano, Form1 is calling Form2"
End Sub
End Class
 
Public Class Form2
Inherits System.Windows.Forms.Form
Shared Frm_Parent As New Form1
#Region " Windows Form Designer generated code "
#End Region
Private Sub Form2_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
Me.ControlBox = False
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub Button_Answer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Answer.Click
Frm_Parent.Frm_1_StatusBar.Text = "Hello Form1, Thanks for calling"
Frm_Parent.Frm_1_StatusBar.Refresh()
End Sub
Private Sub Close_Mdi_Child_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Close_Mdi_Child.Click
Me.Close()
Frm_Parent.Open_Mdi_Child.Enabled = True
End Sub
End Class
 
Last edited by a moderator:
first off, if you could put code between the [ code] and [ /code] tags that would be awsome

ok simple solution here:
add a module to the project and in the module put:
Friend MdiParent As frm_Parent 'or what the actual parent form name is

ok now in the Load event of the parent form put:
MdiParent = Me

now in the child form when you need to do something to the parent form use the MdiParent variable instead
like:
VB.NET:
MdiParent.Open_Mdi_Chile.Enabled = True

also a few coding suggestions, dont use underscores and long names like that
for example the Open_Mdi_Child button's name could be btnOpenChild the "btn" is short for button to help keep code straight and readable for other three letter abbreviations (hungarian notation) like that read this:
http://www.vbdotnetforums.com/showthread.php?t=3875

also
btn - Buttons
lbl - Labels
txt - Textbox's
lst - Listbox's
cbo - ComboBox's
frm - Form's
cn - Connection
da - DataAdapter's
ds - DataSet's
tmr - Timer's
 
Reply Mdi Project

Hello,

Thanks for the response.

I'm sorry but this doesn't work.
When i put MdiParent=Me in the parent form i receive the message:
Additional information: A form cannot be both an MDI child and MDI parent

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
MdiParent =
Me
End Sub

Module
Module1
Friend FrmParent As Form1
End Module

Greetings H.w.Hendrick
 
then change this:

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
MdiParent = [/SIZE][SIZE=2][COLOR=#0000ff]Me
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] 
Module[/COLOR][/SIZE][SIZE=2][COLOR=#000000] Module1[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]Friend[/COLOR][/SIZE][SIZE=2] FrmParent [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Module

[/COLOR][/SIZE][/COLOR][/SIZE]to:
VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Form1_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
   FrmParent = [/SIZE][SIZE=2][COLOR=#0000ff]Me
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 [SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff] 
Module[/COLOR][/SIZE][SIZE=2][COLOR=#000000] Module1[/COLOR]
   [/SIZE][SIZE=2][COLOR=#0000ff]Friend[/COLOR][/SIZE][SIZE=2] FrmParent [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Form1
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Module
[/COLOR][/SIZE][/COLOR][/SIZE]
 
Solution Mdi problem

Hey,
Thanks for response.
This works now.

I have also found a'n other slolution.
VB.NET:
Private Sub Frm_Child_Load([SIZE=2][COLOR=#0000ff]
ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#008000]  DirectCast(Me.MdiParent, Frm_Main).SetText_ToMain("Show existing       Records", 10)
end sub
 
In the Frm_Main form
[SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] SetText_ToMain([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] Text [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] Soort [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Select[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] Soort
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 10
Stb_Main_1_Panel_1.Text = Text
[/SIZE][SIZE=2][COLOR=#0000ff]Case[/COLOR][/SIZE][SIZE=2] 20
[/SIZE][SIZE=2][COLOR=#008000]Stb_Main_1_Panel_2.Text = Text
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Select
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
This works also.

Now an other problem
I wont to use an TEXTBOX in my Frm_Main.statusbar Stb_Main_1_Panel_3 an work with it. so when I put a name in dare en push enter he response through my database en puts the record in my Frm_Child

This was the solution in VB6.0 in the Sub_Main general declarations
Declare Function SetParent Lib "USER32" _
(ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long


In the Frm_Child load event
SetParent Txt_Zoek.hWnd, FrmMdiSWVV2001.sbStatusBar.hWnd

Now in vb.Net i wont to put like this
SetParent(Txt_Search_ByName.hWnd, Frm_Parent.Stb_Main_1_Panel_3.hWnd), but i receive the message Hwnd is not a member.

Question is there now in VB.NET an other solution?

Greetings H.w.Hendrick
[/COLOR][/SIZE]
 
Last edited by a moderator:
Back
Top