CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2010
    Posts
    6

    C# Forms and Text Boxes

    I have a small form with an update button, everytime the user clicks "Add price" I want 2 small text boxes to pop up right next to each other so the user could insert what is needed. If they wish to add another, they click "Add price" and another 2 boxes underneath the previous two show up and so on.
    how would I implement that?

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: C# Forms and Text Boxes

    Personally I would use WPF... but,

    You can add a WrapPanel and set the width to enough where it can only contain two items per row.

    Then, when Add Price is clicked, it would programatically add two textboxes.

    I haven't used a WrapPanel in over a year, I'm assuming it has an Items collection but just look for whatever the container type is, and add TextBoxes that way.

    Code:
    wrapPanel1.Items.Add(new TextBox()) ;
    wrapPanel1.Items.Add(new TextBox()) ;
    However, another solution which may be better, is to create a new usercontrol which is the 2 textboxes. You could add this control over and over, and you can expose the textbox.text property of each textbox in it as you see fit.

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

Featured