Solved

Creating Controls during Runtime possible?

Posted on 1998-12-26
6
190 Views
Last Modified: 2013-11-13
What i want to do is create and slap NEW controls onto my blank form once my app runs. The reason i want to do this is beceause the new controls that are added to the form may repeat, meaning i want it to now alter to become  control arrays. I have no idea how to do this. I am use to just slapping controls onto my form and going but since i want an indeterminite # of repeated instances of these controls i dont have a clue how to begin to do this.
Would it be wise to have the controls already on my form, but all having theire "visible" method set to "FALSE" and then somehow create instances of these controls and then display them?  If this is the case please let me know how to do this.
0
Comment
Question by:aniston
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
jbil earned 20 total points
ID: 1452522
Make a control array ( If you copy a control at design time and paste it VB will ask if you want to create a control array, select yes, then delete the one created leaving you with control(0))
Then at run time load controls as needed.
Then set left, top, visible, ext  props of the newly loaded controls.

This code loads 6 labels from Label1(0)

Dim i
Dim numofcontrols
numofcontrols = 6
    For i = 1 To numofcontrols
        Load Label1(i)
        Label1(i).Left = Label1(i - 1).Left + Label1(i - 1).Width
        Label1(i).Visible = True
    Next i
0
 

Expert Comment

by:ljaques
ID: 1452523
What is weird is when i tried what you said for 6 different types of controls it only displayed the first one and didnt display any others.
I said:

    NumTasks = NumTasks + 1
   
    Load TaskFrame(NumTasks)
    TaskFrame(NumTasks).Caption = "Task " & NumTasks
    TaskFrame(NumTasks).Top = (60 + ((NumTasks - 1) * 1140))
    TaskFrame(NumTasks).Left = 45
    TaskFrame(NumTasks).Width = 2475
    TaskFrame(NumTasks).Height = 1065
    TaskFrame(NumTasks).visible=true
       
    Load StateImage(NumTasks)
    StateImage(NumTasks).Container = TaskFrame(NumTasks)
    StateImage(NumTasks).Picture= ImageList1.ListImages(1).Picture
    StateImage(NumTasks).Left = 60
    StateImage(NumTasks).Top = 270
    StateImage(numtasks).visible=true
   
    Load SiteNameLabel(NumTasks)
    SiteNameLabel(NumTasks).Container = TaskFrame(NumTasks)
    SiteNameLabel(NumTasks).AutoSize = True
    SiteNameLabel(NumTasks).Font.Name = "MS Serif"
    SiteNameLabel(NumTasks).Font.Size = 6
    SiteNameLabel(NumTasks).ForeColor = &H800080
    SiteNameLabel(NumTasks).Caption = "---"
    SiteNameLabel(NumTasks).Left = 585
    SiteNameLabel(NumTasks).Top = 225
    SiteNameLabel(NumTasks).visible=true

Only the TaskFrame control (it is a Frame) was displayed and the others were not. Any answers?
0
 
LVL 3

Expert Comment

by:jbil
ID: 1452524
ljaques,

Your only asking for 1
NumTasks = NumTasks + 1
or 0=0+1=1


for 0 (already loaded) to 6 more use something like this...

Dim NumTasks As Integer
 NumTasks = 1
  Do Until NumTasks = 6
    Load TaskFrame(NumTasks)
    TaskFrame(NumTasks).Caption = "Task " & NumTasks
    TaskFrame(NumTasks).Top = (60 + ((NumTasks - 1) * 1140))
    TaskFrame(NumTasks).Left = 45
    TaskFrame(NumTasks).Width = 2475
    TaskFrame(NumTasks).Height = 1065
    TaskFrame(NumTasks).Visible = True
    NumTasks = NumTasks + 1
   Loop
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Expert Comment

by:ljaques
ID: 1452525
Sorry i forgot to include the loop as you mentioned just above.
My code does look like what you just gave however it only visually displays the TaskFrame and not the other controls that may be inside that loop as well (ie. a Label). Must i use a: Show TaskFrame(numtasks), Show Label1(NumTasks),etc?

0
 
LVL 3

Expert Comment

by:jbil
ID: 1452526
ljaques,
To set container use Set like this, I tried and it worked for me.

Load SiteNameLabel(NumTasks)
    Set SiteNameLabel(NumTasks).Container = TaskFrame(NumTasks)
         
    SiteNameLabel(NumTasks).AutoSize = True
    SiteNameLabel(NumTasks).Font.Name = "MS Serif"
    SiteNameLabel(NumTasks).Font.Size = 6
    SiteNameLabel(NumTasks).ForeColor = &H800080
    SiteNameLabel(NumTasks).Caption = "---"
    SiteNameLabel(NumTasks).Left = 1158 ''5
    SiteNameLabel(NumTasks).Top = 122 '5
    SiteNameLabel(NumTasks).Visible = True
0
 

Author Comment

by:aniston
ID: 1452527
Thanks very much jbil...You are a genius!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question