how to add controls dynamically ? [modified]
-
Hello,everyone!Need help about adding controls.Now I want to do this:if there is one pannel with some controls such as text box or combo box,when I clicked the button "Add" ,a same pannel wiht same controls would display under the first pannel;then the button "Add" go down below the second pannel.Then I clicked button once again,there will be three same peannel. What I should do to achieve this ?Please give me some suggestions!Thanks a lot!
modified on Tuesday, May 18, 2010 10:44 PM
-
Hello,everyone!Need help about adding controls.Now I want to do this:if there is one pannel with some controls such as text box or combo box,when I clicked the button "Add" ,a same pannel wiht same controls would display under the first pannel;then the button "Add" go down below the second pannel.Then I clicked button once again,there will be three same peannel. What I should do to achieve this ?Please give me some suggestions!Thanks a lot!
modified on Tuesday, May 18, 2010 10:44 PM
For a WinForm app, there seem to be two very different ways to add controls to a form: - one is by using the "Visual Designer" - the other is by adding some code that creates and adds controls at run-time. However, the designer basically does two things for you: 1. it adds code to some file, which you may not have seen yet; if your form is called Form1, it consists of several files, including Form1.vb; the designer creates and controls Form1.designer.vb (you may have to fiddle some buttons/settings for Studio to show it in the Solution pane, can't remember the details). 2. and then it lets Studio execute such code, and that is how the controls suddenly appear on you form. (No they are not really drag-and-dropped, your drag operation tells the Designer to add and then execute code!) So the suggestion is clear: do it once with designer, then go and peek inside that auto-generated file. BTW: do not edit the designer files, just learn from them, and add similar things to your code. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).