Results 1 to 10 of 10

Thread: CREATING OBJECTS!!!!!!!!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    77

    Unhappy

    Final plea for help

    Okay now only respond if you KNOW how to do it or you're an experienced programmer and know it's not possible.

    How do you create objects on a form during runtime???

    -Justin

    In a dungeon of Britannia a tamer says, "All Release".

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

    <?>

    I flunked sandbox and since I'm not a programmer I guess I'm ruled out.
    :}
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can only do it if you have at least one of the control type already on the form, as an item in a control array. For example, put a Text Box onto a form, give it an index of 0. Then add this code:
    Code:
    Private Sub Form_Load()
        Load Text1(1)
        Text1(1).Visible = True
        Text1(1).Top = Text1(1).Top + Text1(1).Height + 60
    End Sub
    If you want to create a control without one already present, you'd need to go the api route.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4

  5. #5
    Lively Member
    Join Date
    Jul 2000
    Posts
    94
    If you have VB6 you can use the Controls.add method. You do not need to have a previous control of that type or control array.
    To Create a label on a form:
    Code:
    Dim i As Object
    Set i = Controls.Add("vb.label", "label1")
    i.Visible = True
    i.Caption = "hello"

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Posts
    77

    Thumbs up Thx *Grins*

    Yeah I'll try that...

    I would be playing an online game right now but I'm on vacation using a slow *zz notebook (excuse Moi Francais).

    Thx a lot 8].

    -Justin

    Newb - "Hey...I got the best connection. I just upgraded from a 28.8 to 56kbps"
    Gimp - "Wazzup...I Just got a T1 for my Network. The cable was too slow :>"

  7. #7
    New Member
    Join Date
    Aug 2000
    Posts
    10
    you cannot manufacture controls just from nothing... i think... but since i'm not a top-class programmer, how should i know...

    1. Place a label on the default form
    2. Set the index to zero
    3. paste this code where you want to create the object / control..

    Load Label1(1)
    Label1(1).Left = 1000
    Label1(1).Top = 1000
    Label1(1).Visible = True ' you need this. as default, its false

    to get rid of it again...
    unload label1(1)

    martin

  8. #8
    Guest
    What are you talking about? MartinLiss provided a way for creating controls from "nothing".

    However, if you don't have VB6, you can still create them from scratch 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
    Const WS_CHILD = &H40000000
    
    Private Sub Form_Load()
        retval = CreateWindowEx(0&, "Button", "Button1", WS_CHILD, 32, 32, 64, 64, Me.hwnd, 0, App.hInstance, ByVal 0&)
        ShowWindow retval, 1
    End Sub

  9. #9
    Addicted Member
    Join Date
    Aug 2000
    Location
    Columbus Ohio
    Posts
    217
    If I am using VB5 is there a way to use something like controls.add w/o using the windows API?
    Chris

    [email protected]
    Windows XP RC2 B2526
    Visual Studio.Net Beta 2
    C++, VB, VB.Net, ASP, PHP

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Not really, which is probably why MS put it into VB6. Anyway, once you're used to it, using the API for things like this isn't that bad. Anyway, just use the "Load xx(1)" method, but have xx(0) as not visible on the form at startup. The end-user will never know the difference, and you won't really care.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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