Results 1 to 10 of 10

Thread: dont ask why!

  1. #1

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    Talking

    can you insert/create frames, buttons and such like with code, whilst your running a program.
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

  2. #2
    New Member
    Join Date
    Oct 2000
    Posts
    10
    I think so,but i don't know how.

    The way i do it if i have programs that need it to to draw the control or controls on the form, make them invisable and make them single element control array (just add a 0 to the index value)

    Then you can

    Code:
    Load Button(new index no)
    
    'and
    
    unload Button(index of button to remove)
    you can add the code for the buttons and such at design time easily then.

  3. #3
    Hyperactive Member
    Join Date
    May 2000
    Posts
    344

    Not sure

    I don't think you can, but like the above person said if you know the largest amount of labels/buttons for example your gonna use on the app then you can use visible function.

    Label1.visible = false
    'and whenever you actually want it to show
    label1.visible = true


    If its a lot of labels, and you dont want to see all them cluttered at design time......you can also tell it what width and height to be at but would be a lot of code if a lot of controls. Hope that helpz.
    -RaY
    VB .Net 2010 (Ultimate)

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Yes..this example is a button

    Code:
    'VB6
    ' Remarks:
    ' Dynamically add a new button to the form. The
    ' item to add, a button in this case, must be a
    ' member of the VB object as displayed in the
    ' Object Browser.  The second parameter is the
    ' the new control's name.
    '------------------------------------------------------------
    'on the form add 2 command buttons...cmdQuit and cmdRemove
    'height of form 2600...width 4400..put buttons lower left
    'buttons...height = 324...width = 1600
    '
    
    Set btnObj = Controls.Add("VB.CommandButton", "btnObj")
    Private WithEvents picObj As CommandButton
    '
    With btnObj
        .Visible = True
        .Caption = "&Dynamically Added Button"
        .Top = 100
        .Left = 2222
        .Width = 1600
        .Height = 324
    End With
    
    End Sub
    
    Private Sub btnObj_Click()
    '
    ' Respond to the new button's Click event.
    '
    MsgBox "This button was added at run time!"
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    New Member
    Join Date
    Oct 2000
    Posts
    10
    Thats not what i said.

    You only need one invisable button to load up and max of 32k buttons and each one you load up you can set the different propties.

    They will all have the same code thou, but with an Index value added to each event

    For Example

    A Single Button has the following click Event:

    Code:
    Private Sub Command1_Click()
    
    End Sub
    While a Single Button in a control array has the following click Event:

    Code:
    Private Sub Command1_Click(Index as Integer)
    
    End Sub
    So you have one button Invisible

    If you want to load a button or two at run time then you do this:

    Code:
    Load Command1(1) 'This will make a new button with index of 1
    Command1(1).left = X 'Need to setup up All differences
    Command1(1).visible = true 'New controls will ALWAYS be invisable
    If you do it with Frames only the Frame only the frame and not its contents will be cloned., but if you do it to each control within a frame then they will remain part of the frame when cloned.

    An exception to think i think (don't quote me) is forms, if you load a copy of a form, all its controls get cloned aswell.

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Nicer, nicely put.
    If you are using an array of a control, you need a control with an index of 0.
    If you just want to add a control then you don't need one present as the object can be created dynamically at run time.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  7. #7

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    Thanks

    thank you all for your input.

    i didnt want to start an argument but i think ill use joes method.

    thanks again ...
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

  8. #8

    Thread Starter
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179

    quick Q

    will it work in vb5 as your rem said vb6
    Due to the energy crisis, the light at the end of the tunnel has been turned off.
    Sorry for any inconvenience this may cause

  9. #9
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    I'm not sure on that one...some things I have documented as only VB6...this one I didn't but for some reason I think it is only vb6....not hard to test if you have vb5...if it doesn't work it's 6.

    If it is 6 only and all you have is 5 do a search on dynamic and use Megatron as user name to search on. I've seen postings by him using vb5 to add controls dynamically.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  10. #10
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    My code is VB6 only.

    Here is Megatron's for vb5

    For VB5, you can create buttons at runtime. It just involves manually using the CreateWindowEx API.

    Code:
    Private Declare Function CreateWindowEx Lib "user32" Alias "CreateWindowExA" (ByVal dwExStyle As Long, ByVal lpClassName As String, ByVal lpWindowName As String, ByVal dwStyle As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, lpParam As Any) As Long
    Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
    Private Const WS_CHILD = &H40000000
    Private BTN As Long
    
    Private Sub Form_Load()
        BTN = CreateWindowEx(0, "Button", "Button1", WS_CHILD, 32, 32, 64, 64, hwnd, 0, App.hInstance, ByVal 0)
        ShowWindow BTN, 1
    End Sub
    __________________
    Megatron
    [email protected]
    Visual Basic 5 SP3
    See the VBFE Library


    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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