How do you set a form's properties from another form? I know in 6.0 it would be something like this, but it doesn't work in .NET:
Thanks in advance,Code:FormName.Property = Value
Furry
Printable View
How do you set a form's properties from another form? I know in 6.0 it would be something like this, but it doesn't work in .NET:
Thanks in advance,Code:FormName.Property = Value
Furry
quite few changes in .net
Not quite what I wanted, but thanks for your reply.
I think the fault is with me for not explaining that it gives me this error when I try to set those properties:
Any Ideas?Quote:
Reference to a non-shared member requires an object reference.
Furry
Try this:
http://www.vbforums.com/showthread.p...hreadid=205998
It sounds like you are using the formname instead of the instance variable.
you cant acess the forms like vb6 because they are not declared globally. They are just like any other classes that you create. You could create your form in a module so it would be accesibble to your project publicly though
So this is what I'd use to make it public?Quote:
Originally posted by Edneeis
Try this:
http://www.vbforums.com/showthread.p...hreadid=205998
It sounds like you are using the formname instead of the instance variable.
VB Code:
Dim frm as New Form2
You're probably going to consider me a newbie from now on, but, what's a module? :confused:Quote:
Originally posted by MrPolite
you cant acess the forms like vb6 because they are not declared globally. They are just like any other classes that you create. You could create your form in a module so it would be accesibble to your project publicly though
Well a module is like an all shared class so it is global to the application and you don't make objects from it. When you go to 'Add a New Item...' you'll see it here in the dialog that pops up.
http://www.vbforums.com/attachment.p...postid=1221704
I'm a big fan of the End Result, if it gets the job done then don't sweat the details let me do it how I want, and not all rules apply all the time (hence the phrase 'general' rule), BUT..
It is more OOP like to avoid modules, they make these stateless unmanaged objects sort of and usually aren't really needed. Sometimes they are and I don't think its of the devil to use them, but you should see what other ways there are of doing things.
Most applications have a 'main' form and the rest of the application branches from it. So usually you can overload the constructor of a any 'sub' form to pass it the 'main' form and since the 'main' form started the 'sub' form it already has access to its properties and public members.
VB Code:
'add to SubForm Private frm as Form Public Sub New(frm as Form) 'you can use the actual form name if you know it Mybase.New() New() Me.frm=frm End Sub 'then when the main form creates it dim frm As New SubForm(Me) frm.Show()
There are other ways with delegates and what not if you need to do something more specific too.
I only write this because this seems to be a very common question. As I said I don't think there is anything really WRONG with doing it the old way (modules) but what if modules aren't in the next version of vb or what if you switch languages to something that doesn't have them. Or just to jive with the whole .NET wave.
Or you could create a class with all static members. This is what a module boils down to, which is also more OOP oriented.
Ah, thankyou all for your help. I've gotten my answer. It was in that code that I asked about before.
VB Code:
Dim frm as New Form2
The name of my form is frmResults. This is the code I used:
VB Code:
Dim frmResults as New frmResults
And now I can set all the properties of the form and its contents. The reason I asked if it was possibly what I needed instead of trying it was because I was at Tae Kwon Do at the time.
Thanks again for all you guys's help.
Furry