Results 1 to 10 of 10

Thread: Setting other forms' properties...

  1. #1

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171

    Question Setting other forms' properties...

    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:

    Code:
    FormName.Property = Value
    Thanks in advance,
    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    quite few changes in .net
    Attached Files Attached Files

  3. #3

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    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:
    Reference to a non-shared member requires an object reference.
    Any Ideas?


    Furry
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Try this:
    http://www.vbforums.com/showthread.p...hreadid=205998

    It sounds like you are using the formname instead of the instance variable.

  5. #5
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    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
    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!!

  6. #6

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    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.
    So this is what I'd use to make it public?
    VB Code:
    1. Dim frm as New Form2

    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
    You're probably going to consider me a newbie from now on, but, what's a module?
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

  7. #7
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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.


  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    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:
    1. 'add to SubForm
    2. Private frm as Form
    3.  
    4. Public Sub New(frm as Form) 'you can use the actual form name if you know it
    5.    Mybase.New()
    6.    New()
    7.    Me.frm=frm
    8. End Sub
    9.  
    10. 'then when the main form creates it
    11. dim frm As New SubForm(Me)
    12. 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.

  9. #9
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Or you could create a class with all static members. This is what a module boils down to, which is also more OOP oriented.

  10. #10

    Thread Starter
    Addicted Member Fat_N_Furry's Avatar
    Join Date
    Oct 2002
    Posts
    171
    Ah, thankyou all for your help. I've gotten my answer. It was in that code that I asked about before.

    VB Code:
    1. Dim frm as New Form2

    The name of my form is frmResults. This is the code I used:

    VB Code:
    1. 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
    Eat long and prosper!
    If someone helps you, find someone you can help.
    If you still have time, click on the darn banner up there and help the forum!

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