Results 1 to 12 of 12

Thread: access other form's proprieties

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    access other form's proprieties

    i have form1 and form2..both are loaded..i click in form2's button and then i want that form1.text's gonna be "hi"...how do i do that?

    i tryed dim mform1 as new form1()
    form1.text = "hi"
    but its quite obvious that it didnt work cuz that would only work with a new form...not an already created one...so..how do i do this?

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    I'd really like to know a good way to do this. You could pass the form to form2's constructure.... but I dont like the idea...

    Would it be bad to make a module and declare some of the forms are public variables and then load the forms from the module? this way the forms can access each other...
    I tried making a sub main in a module, but as soon as the module ends, the forms get unloaded. I guess I have to make some threads or something. How could I do this?
    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
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    I'm working with an application that has about ten forms that all manipulate and display data between each other. What I've been doing (no clue if this is the "right way") is using a public DataSet declared in a module, and then once the main form is loaded it calls a sub in the module to initialize the dataset. For my purposes this works really just the way I want it to; for each of the forms, as they load they go and fill their contents from tables in the DataSet, and changes made are displayed on other forms as they get the focus back (the .Activated base event for the form).

    Of course this may be a completely crackheaded way to do it for many apps, but for me this really does the trick.

  4. #4
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    You can do what slow_learner said or you can declare public properties in the forms to expose the private variables.
    Dont gain the world and lose your soul

  5. #5
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    I still don't see what is wrong with passing references through the constructor. If you have a main form that is central to your app, but have other dialogs and such that will manipulate the main form's properties, controls, etc. passing a reference just makes sense.

    Now if your application requires more than one form as the main workspace, and they are switched between equally, then keeping track of those forms in module would be benificial. You can make them static properties in a static class (module for VBers).

  6. #6
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    For me, the reason I'm using a DataSet to store all my junk is because my data's all tabular, with a varying number of user-defined records, with changes on one table cascading changes into another table(s). I can't imagine how much harder it would have been without dataset event handlers (I suspect quite out of the range of my limited abilities )

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    well, let's say I have a form which asks the user for some numbers, and strings. When the form is closed, I want it to return the results to the main form..... should I just use a module to store the data?



    one more question:
    It's kinda hard for me to explain this. Let's say the default constructor of my form is getting an integer as refrence. Is there away to modify this variable outside the constructor AND make the changes affect the original variable?
    VB Code:
    1. Private myInt as integer
    2. Public Sub New(ByRef anInt as integer)
    3.       myInt = anInt
    4. End Sub
    5.  
    6. Private Sub mySub ()
    7.       myInt = 0        'I want this to change the original variable that was passed to this form. but how?
    8. End Sub
    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!!

  8. #8
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by MrPolite
    well, let's say I have a form which asks the user for some numbers, and strings. When the form is closed, I want it to return the results to the main form..... should I just use a module to store the data?
    There are several ways you can do this. First, you can pass a reference to the data collection form of the main form. Have properties on the main form that the data collection form can set with the variables it collects before unloading.

    Second, you can have a module with variables that it sets. This will require you to go outside the main form to get the variables needed, but still no big deal.

    I pretty much think that it really doesn't matter too much. Either way is probably just as efficient as the other. I personally think adding a couple properties to a form, then sending the reference to the dialog form is easiest for me. Depends on how far you want to spread out your app (forms, modules, etc).

  9. #9
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by hellswraith
    There are several ways you can do this. First, you can pass a reference to the data collection form of the main form. Have properties on the main form that the data collection form can set with the variables it collects before unloading.

    Second, you can have a module with variables that it sets. This will require you to go outside the main form to get the variables needed, but still no big deal.

    I pretty much think that it really doesn't matter too much. Either way is probably just as efficient as the other. I personally think adding a couple properties to a form, then sending the reference to the dialog form is easiest for me. Depends on how far you want to spread out your app (forms, modules, etc).
    you said data COLLECTION form, and that reminded me to take a lookie at collections what are they anyways? just a collection of objects? something like arraylists?
    anyways I got it to work by using a collection (just declared a public variable in my second form and modified that..)
    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!!

  10. #10
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually I would use a delegate for this, it'd be perfect.

    http://216.26.168.92/vbworld/code.aspx?id=184

    It kind of works like a function pointer (but don't get confused by the sound of that). You are basically passing a method from the main form to the child form and the child form calls it to update the data. I'm not going to post an example because there is one at the link.

  11. #11
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Never thought about using a delegate, good thing to remember.

  12. #12
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Originally posted by MrPolite
    you said data COLLECTION form, and that reminded me to take a lookie at collections what are they anyways? just a collection of objects? something like arraylists?
    anyways I got it to work by using a collection (just declared a public variable in my second form and modified that..)
    I meant just a general form that collects data for your app to process. I wasn't refering to the collection class.

    A collection is just a class that you can add objects to as you stated. I believe that the arraylist is a child of the collection class. There are a few different types of collections that are optimized for different situations. Basically they work like the form collection, or control collection in VB6, but you control more of the process.

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