Results 1 to 3 of 3

Thread: just starting a multiple form project

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Posts
    262

    just starting a multiple form project

    Okay a question which has been asked a million time before, but what is the correct way to access items ect between forms previously I've done this?


    VB Code:
    1. Public Class frmcall
    2.     Inherits System.Windows.Forms.Form
    3.     Dim form1 As Form1
    4.  
    5.     Private Sub frmcall_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    6.  
    7.         form1 = DirectCast(Me.Owner, Form1)
    8.     End Sub
    9.  
    10.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    11.         MsgBox(form1.BindingContext(form1.ds, "employees.SMS").Current())
    12.  
    13.         MsgBox(Form1.cbocompany.Text)
    14.     End Sub
    15. End Class
    Which allows me to access all the components of Form1, just really want to check this is the correct way of doing it, as may as well get things right from the start.

  2. #2
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Re: just starting a multiple form project

    A pretty easy way is just to add a Main Module. In the Main Module declare:

    VB Code:
    1. Public MainForm As FormMain

    Then in the load event of the main form:

    VB Code:
    1. MainForm = Me

    Now MainForm will be an accessible reference in all of your forms. Any Public property, event, method will be exposed.

    --Christian
    In life you can be sure of only two things... death and taxes. I'll take death.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: just starting a multiple form project

    You should NOT be using the Owner property unless you specifically want to create an owned form. If you don't know what an owned form is then it's safe to say that you don't want that functionality. I suggest you read the tutorial on the first line of my signature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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