Results 1 to 2 of 2

Thread: MDI Form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    MDI Form

    Hi All;
    I have a MDI application with some menus to load some child forms. I used to disable the menu after the child form loaded. I couldn't access the menus except if the form is child but I want to access some menus and public subs in the MDI form from another child or none child form. How could I do that.
    Note: I use DirectCast from the child form to access a MDI form's menus.

  2. #2
    Hyperactive Member fret's Avatar
    Join Date
    Sep 2004
    Posts
    472

    Re: MDI Form

    I'm not clearly understand your problem but try to get some idea with this, hope this would help.
    your trying to disable some menus and in the MdiParent whether the form is child or not.

    in the main form:
    VB Code:
    1. ' MenuItem2 used to open Form2 as child of Form1
    2.     Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem2.Click
    3.         Dim frm2 As New Form2
    4.         frm2.MdiParent = Me
    5.         frm2.Show()
    6.     End Sub
    7.  
    8.     'Sample Public
    9.     Public Sub hello()
    10.         MessageBox.Show("hello world")
    11.     End Sub
    12.  
    13.     ' MenuItem3 used to open Form3 not a child of Form1
    14.     Private Sub MenuItem3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MenuItem3.Click
    15.         Dim frm3 As New Form3
    16.         Me.AddOwnedForm(frm3)
    17.         frm3.Show()
    18.     End Sub

    in your form2:
    VB Code:
    1. Dim frmMain As Form1 ' Form1 is the MdiParent
    2.     Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         frmMain = DirectCast(Me.MdiParent, Form1)
    4.         frmMain.MenuItem2.Enabled = False ' disable the menu(MenuItem2) from the Form1 which is the MdiParent
    5.     End Sub
    6.  
    7.     Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    8.         frmMain.hello() ' access sample public sub in the Form1 which is the MdiParent
    9.     End Sub

    in your form3:
    VB Code:
    1. Dim frmMain As Form1 ' Form1 is the MdiParent
    2.     Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    3.         frmMain = DirectCast(Me.Owner, Form1) ' frmMain is the owner of this form(Form3)
    4.         frmMain.MenuItem3.Enabled = False ' disable menu(MenuItem3) from the MdiParent
    5.     End Sub
    6.  
    7.  
    8.     Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    9.         frmMain.hello()
    10.     End Sub


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