Results 1 to 5 of 5

Thread: enabeling controls question

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    13

    enabeling controls question

    how can i reference controls on one form to enable them from anotehr form?

    assuming I'm missing a dim statement someplace or something in the syntax but so far every thing that i've tried i've gotten some form of an error when trying to.

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    Re: enabeling controls question

    Originally posted by ronman1123
    how can i reference controls on one form to enable them from anotehr form?

    assuming I'm missing a dim statement someplace or something in the syntax but so far every thing that i've tried i've gotten some form of an error when trying to.
    UMM you have to have access to the form... you can declare a public variable in a module and set it equal to your form, ie
    public mainForm as form

    and in your main form set mainForm=me
    then you can access it from the second form....

    you could also change the New constructor of your second form to accept a variable of type form, and pass the main form to the new constructor
    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

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    13
    im sure it's probably the wrong way of doing but i've declared each new form in the form that i'm calling it from.

    though your last comment confused me though

    "you could also change the New constructor of your second form to accept a variable of type form, and pass the main form to the new constructor"

    sorry for waht i know is such a simple question. was mostly self taught at vb 6 and am now struggeling through my first .net project. but the help is much appreciated

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by ronman1123
    im sure it's probably the wrong way of doing but i've declared each new form in the form that i'm calling it from.

    though your last comment confused me though

    "you could also change the New constructor of your second form to accept a variable of type form, and pass the main form to the new constructor"

    sorry for waht i know is such a simple question. was mostly self taught at vb 6 and am now struggeling through my first .net project. but the help is much appreciated
    sorry I'm reinstalling vs.net now so I cant write an example, sorry if I confused you

    say this is your second form. if you open up the region where it says "Windows Form Designer generated code " you'll see the New constructor. You can change it to something like this:
    VB Code:
    1. ' in the second form:
    2.     Private callerForm as form
    3.  
    4. #Region " Windows Form Designer generated code "
    5.     Public Sub New(byval callerForm as form)
    6.        me.callerForm = callerForm
    7.        '.....
    8.     End Sub
    9. ....
    10. .....
    11. ......
    12. #End Region
    13.    
    14.     private sub foo()
    15.         ' you can access the other form like this
    16.         callerForm.text = "boo"
    17.    end sub

    hope this explains it sorry I'm kinda bad in explaining something, hehe



    edit: when you're creating a new form you have to pass the caller form to new(). IE, if your second form is called frmSecond and you are creating an instance of it, you should do something like this
    VB Code:
    1. dim frm as new frmSecond (me)    ' pass "me" to the constructor
    2. frm.show()
    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!!

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2003
    Posts
    13
    okay i see what you were getting at

    thanks much for the quick replies and the help

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