Results 1 to 6 of 6

Thread: Calling a sub from a parent form

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    32

    Calling a sub from a parent form

    How can i call a sub from a parent form ?

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    what do you mean by parent form? you mean the MDI form stuff?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Member
    Join Date
    Jul 2002
    Posts
    32
    I have a main form that starts another form, and in this new form i would like to call a sub from the main form .

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    aah, I havent worked with delegates.
    You can pass the sub in the main for as a delegate to the second form and then call it from the second form.
    You could also pass the main form to the second form, which isnt a very good thing to do
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  5. #5
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Pass a reference of the main form to the second form by modifying sub new in the second form:-

    'second form
    'declare a private variable as whatever main form is called
    Private _MainForm as form1

    Public Sub New(Mainform as form1)
    _MainForm = MainForm
    MyBase.New()
    End Sub

    'main form
    'pass the reference to the main form
    dim SecondForm as new form2(me)
    SecondForm.Show()

    Now in the second form you can call any public method :-

    _MainForm.DoSomething

    You can have as many versions of the New procedure as you want as long as they have different signitures (like any method) so you could have New procedures that accept any object you need to pass to it.

  6. #6
    Fanatic Member khalik_ash's Avatar
    Join Date
    Aug 2002
    Location
    Singapore
    Posts
    724
    hi

    i have some thing similar to this but i have a public sub in all my forms how do i call from mdi....


    calling sub of mdi child from the parent mdi..

    in vb6 we do me.activeform.assign (assign is the public sub)

    in vb.net....?

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