|
-
Sep 29th, 2002, 07:57 AM
#1
Thread Starter
yay gay
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?
-
Sep 29th, 2002, 12:49 PM
#2
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!!
-
Sep 29th, 2002, 01:01 PM
#3
Fanatic Member
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.
-
Sep 29th, 2002, 03:49 PM
#4
Frenzied Member
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
-
Sep 29th, 2002, 04:09 PM
#5
PowerPoster
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).
-
Sep 29th, 2002, 04:40 PM
#6
Fanatic Member
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 )
-
Sep 29th, 2002, 06:14 PM
#7
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:
Private myInt as integer
Public Sub New(ByRef anInt as integer)
myInt = anInt
End Sub
Private Sub mySub ()
myInt = 0 'I want this to change the original variable that was passed to this form. but how?
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!!
-
Sep 29th, 2002, 06:21 PM
#8
PowerPoster
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).
-
Sep 29th, 2002, 07:02 PM
#9
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!!
-
Sep 29th, 2002, 09:45 PM
#10
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.
-
Sep 29th, 2002, 10:05 PM
#11
PowerPoster
Never thought about using a delegate, good thing to remember.
-
Sep 29th, 2002, 10:12 PM
#12
PowerPoster
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|