Results 1 to 3 of 3
  • Thread Tools
  1. 5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    referring to Forms in Module (VB.Net)

    I am starting a .Net program which is a WIndows Form application. I have one form with three parts to it (treeview, tab control, data grid). The form is its own class of course so I have code to handle the various events I want to deal with. I then added a Module to do some of the housekeeping. How do I refer to the form (and its controls) from within the Module? I've done this with Excel VBA but don't know the right method for .Net environment.Something like this:
    <pre>public class fMain
    ' code with events for form fMain
    me.trVariables.blah.blah ' sample, talk to tree view control
    end class</pre>

    <pre>Module Util
    ' code to read/write to pieces of the form (tabbed control and data grid mostly)
    THE_FORM.what.what ' method to talk to the form fMain THE MISSING LINK!
    end Module</pre>

    From the Module I want to write code to populate the various fields of the tab control based on various user actions. I know I could put all the code i the form class but that's not exactly good style (90% of my program would be in this class if I did it that way *ha*). I'm very familiar with C/C++ and classes and all that stuff but am stuck on the proper methodology for .Net

    Thnx, Deb

  2. Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 27 Times in 26 Posts

    Re: referring to Forms in Module (VB.Net)

    Deb,

    Try something like this:

    In the main form (in this case called 'Form1') you can have code like this:

    <pre> Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles btnTest.Click
    Call AffectTheForm(Me)
    End Sub</pre>

    Then in a regular code module, you can have this:

    <pre> Public Sub AffectTheForm(ByVal Form As Form1)
    Form.lblChangeText.Text = "Text has changed"
    End Sub</pre>

    Gary

    PS: You can use this same method in Excel, Word etc. VBA.

  3. 5 Star Lounger jujuraf's Avatar
    Join Date
    Jun 2001
    Location
    San Jose, California, USA
    Posts
    1,061
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: referring to Forms in Module (VB.Net)

    ahhh, yes that was TOO simple. I was trying to complicate the matter. <img src=/S/bullseye.gif border=0 alt=bullseye width=45 height=15>

    Thanks for clearing the fog.

    Deb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •