CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How to get a control array on a form

  1. #1
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,539

    How to get a control array on a form

    Hi friends !
    A bunch of I'm frightened simple questions regarding programming in C#. Sorry for I'm a real beginner now.
    1) How can I do an array of the same controls on the form. In VB that was easy I had only to set an index and the control was part of an array like TextBox(0), next was TextBox(1)... But there is no index in the controls properties.
    2) When I build a Userdefined control I had to build a propertybag in VB and I remember it was similar in C++ to get the property-settings stored. So how is this arranged in C# controls ?
    3) How I'm able to fix the height of my control ? Is there a resize messsage handler in the Userdefined Control, where I can correct any attempts of the user to size a control vertically. ?
    4) I have learned [Browseable] for getting a Property to be seen in the properties list. How to get properties only visible in the intelisense when coding, but not in the properties. Is this using browseable(false ) ?

    There are lots of such questions upcoming during trying to follow the MS book learning C# step by step and doing my own examples for getting trained. But thats all for this moment. Thx in before.

    Jonny Poet
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  2. #2
    Join Date
    Oct 2001
    Posts
    80

    Re: How to get a control array on a form

    1) There might be a simpler solution but this works
    Code:
    ArrayList l_alMyTextBoxes = new ArrayList();
          
          //here you fill the array with controls that are textboxes
          foreach ( Control c1 in this.Controls )
          {
            if ( c1 is System.Windows.Forms.TextBox )
            {
              l_alMyTextBoxes.Add ( c1 );
              //MessageBox.Show ( c1.Name );
            }
          }
    
    	  //here you loop ever them
          foreach ( TextBox tb in l_alMyTextBoxes )
          {
            MessageBox.Show ( tb.Name );
          }
    2) Have look at the resourcemanager class

    3) A User control has a resize event handler in wich you can handle this.

    4) If you omit [Browseable], you won't see it in the VS designers propertylist, but you will still see it and access it in the code ( Intellisense ).

    Hope this is some help

  3. #3
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,539

    Re: How to get a control array on a form

    Quote Originally Posted by bewa
    1) There might be a simpler solution but this works
    That means I cannot do it with the designer I have to set them by code, isn't it. I heave thought that this is maybe the point, as I havn't found a designer drawn solution in any book.
    Quote Originally Posted by bewa
    2) Have look at the resourcemanager class....
    I'll do that. All other points are clear now,I only didn't find the event handlers generally. IN VB I have had them in the right combobox on tob of the editor, where do I find them here. I have looked around and didn't see them. Do I need to open a speciic panel for that ?
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

  4. #4
    Join Date
    Apr 2005
    Posts
    576

    Re: How to get a control array on a form

    Event handlers can easily be accessed in the events tab of the property window for the control.
    Last edited by klintan; September 1st, 2006 at 02:01 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)