Results 1 to 7 of 7

Thread: change a property of an item in MdiParent

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    change a property of an item in MdiParent

    hi all,

    using a plugin architecture, i created a Form Class that holds the Mdi Form. it has menustrip, toolstrip and statusstrip.

    child forms are created as class and are loaded into the Mdi Form at runtime.

    using interface, i was able to execute subs and functions of a child in the Mdi Form and vice versa.

    now i need to change property values.. to be exact, i need to change the enabled property of the toolstrip buttons depending on which child form is activated using the form_activated event of the child form.

    the problem i now have is how to change the property of the toolstrip item in the Mdi Form.. should i be using interface on this as well by creating subs in the interface and have the Mdi Form implement this interface?

    or can i use Property classes for this?

    thanks

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: change a property of an item in MdiParent

    ChildForm.MdiParent gives you the reference to the parent mdi form. You just cast it to the actual type of your mdi parent and then you can access its members. For exmaple, if I have Form1 is the mdi parent and Form2 is an mdi child, in Form2, I can do:
    Code:
    Dim myParent As Form1 = DirectCast(Me.MdiParent, Form1)
    myParent.Text = "Hello, how are you doing?"
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    Addicted Member
    Join Date
    Sep 2007
    Location
    Right behind you
    Posts
    170

    Re: change a property of an item in MdiParent

    you can also raise an event on your child form and catch it on the parent, so you can continue execution without worrying about how much the parent has to change before you continue.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: change a property of an item in MdiParent

    Quote Originally Posted by stanav View Post
    ChildForm.MdiParent gives you the reference to the parent mdi form. You just cast it to the actual type of your mdi parent and then you can access its members. For exmaple, if I have Form1 is the mdi parent and Form2 is an mdi child, in Form2, I can do:
    Code:
    Dim myParent As Form1 = DirectCast(Me.MdiParent, Form1)
    myParent.Text = "Hello, how are you doing?"
    hi,

    thanks for the reply..

    was just wondering that since this is a plugin architecture, i won' be able to do

    Code:
    Dim myParent As Form1 = DirectCast(Me.MdiParent, Form1)
    since Form1 (Name of MdiParentForm) will not be accessible at design time.

    or is this not the case?

    Quote Originally Posted by winsrp View Post
    you can also raise an event on your child form and catch it on the parent, so you can continue execution without worrying about how much the parent has to change before you continue.
    i will try to dig more about this raise event... first time hearing it

    thanks

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: change a property of an item in MdiParent

    hi all,

    i've been trying to study raising events but i just don't get it...

    i've been reading this sample here..

    http://msdn.microsoft.com/en-us/library/9aackb16.aspx

    but i don't see how to apply this to my situation.

    can someone explain how this is done?

    thanks.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

  6. #6
    Addicted Member
    Join Date
    Sep 2007
    Location
    Right behind you
    Posts
    170

    Re: change a property of an item in MdiParent

    example
    mdi parent code

    vb Code:
    1. private sub call_child()
    2.   Dim Childform As New FRM_MDICHILD
    3.   AddHandler Childform.NewEvent, AddressOf A_Sub_On_Myself
    4.   Childform.MdiParent = Me
    5.   Childform.Show()
    6. end sub
    7.  
    8. private sub A_Sub_On_Myself(some_value as integer)
    9.   label1.text = some_value
    10. end sub

    mdi child code

    vb Code:
    1. Public Event NewEvent(ByVal Info As Integer)
    2.  
    3. private sub extensive_operation
    4.   for x as integer = 0 to 1000
    5.     raiseevent NewEvent(x)
    6.   next x
    7. end sub

    so when the child calls the raiseevent, it sends the value of X, out to the world, since this event has a handler on the parent, and it will be caught and sent to the sub that was designated to process that event.. which in this example will change the value of a label.

    Hope it helps.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    403

    Re: change a property of an item in MdiParent

    thanks... i might be able to come up with something thru this.

    VB Version: Microsoft Visual Studio 2008 Professional Edition
    .NET Version: Microsoft .NET Framework Version 3.5
    OS: Windows XP SP3

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