Results 1 to 8 of 8

Thread: Get all control on a form

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58

    Get all control on a form

    IS there a quick and easy way to get all controls on a form?
    -------------------------------
    StupidMonkee

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    form.controls?
    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
    Addicted Member
    Join Date
    Mar 2001
    Location
    Devon, UK
    Posts
    181
    The form.controls only returns the controls that the form is parent of, it won't return child controls on that control.
    The answer is I don't know if there is an easy way(would like to know one though!) At present I think you need to create a custom collection and add each control to it. See the post on text box controls for the code, which is around here somewhere.
    Wind and waves resolves all problems.

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58
    Originally posted by cim3
    The form.controls only returns the controls that the form is parent of, it won't return child controls on that control.
    The answer is I don't know if there is an easy way(would like to know one though!) At present I think you need to create a custom collection and add each control to it. See the post on text box controls for the code, which is around here somewhere.
    Ok i might be naive here but im not sure which are parent/child controls. I want to get a list of all (let's say) command buttons that are on the form? Are these children? Or will form.controls work?

    My inclination is that it woudl work but i'm not near my computer
    -------------------------------
    StupidMonkee

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Why couldn't you loop through all controls on the form and examine each one and check to see if it has anything in *its* Controls collection?

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If the button is on the form itself not on a tabcontrol or another control that is on the form then Me.Controls will work for you. I agree with Slow_Learner just use recursion. I guess you are going to have to change your name soon Slow_Learner

  7. #7
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    How can I take a name like Captain Wiseass when I neglect to note that all Controls have a HasChildren property?

    ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemwindowsformscontrolclasshaschildrentopic.htm

    thanks though

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2002
    Posts
    58
    Originally posted by Slow_Learner
    Why couldn't you loop through all controls on the form and examine each one and check to see if it has anything in *its* Controls collection?

    I was not talking about the technique here, i simply needed to knwo if a form.controls woudl return a list with (for example command buttons) in it. I woudl obviously loop to find the exact one i needed. the haschildren was key, thanks.

    thanks though guys.
    -------------------------------
    StupidMonkee

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