Results 1 to 3 of 3

Thread: dynamicly add my custom control

  1. #1

    Thread Starter
    Fanatic Member carlblanchard's Avatar
    Join Date
    Sep 2003
    Location
    Bournemouth (UK)
    Posts
    539

    dynamicly add my custom control

    hi all i have made a control which is just a ui feature
    however i would like to create the UI Control ex number of times in my form

    i guess something like this

    Dim HealthCtl As Control

    For i As Integer = 1 To 5
    HealthCtl = New HB_Server.Health
    HealthCtl.Name = "HealthCtl" & i
    HealthCtl.Location = New System.Drawing.Point(8, i & 8)
    HealthCtl.Show()
    Next

    but i dont think its right Can someone help me

    thanks in advance
    I am curretly building a defect management system for software and web developers,
    If you wana try it out (beta test) and keep it for free just send me a message

  2. #2
    Hyperactive Member
    Join Date
    Jun 2002
    Location
    midewest u.s.
    Posts
    275

    Re: dynamicly add my custom control

    I know you can just create a new instance of your control specifically like this

    For i As Integer = 1 To 5
    dim HealthCtl as New HB_Server.Health
    HealthCtl.Name = "HealthCtl" & i
    HealthCtl.Location = New System.Drawing.Point(8, i & 8)
    HealthCtl.Show()
    Next


    instead of

    Dim HealthCtl As Control

    For i As Integer = 1 To 5
    HealthCtl = New HB_Server.Health
    HealthCtl.Name = "HealthCtl" & i
    HealthCtl.Location = New System.Drawing.Point(8, i & 8)
    HealthCtl.Show()
    Next
    That is how i have used dynamic controls before. hope that helps a little




    Edit: I don't know how well that HealthCtl.Location line will work. "i & 8" I assume would "add" i and 8 so on 1 it would be 9... All your controls (if taller than 1 pixel) will overlap. in which case you can use multiplication.

    HealthCtl.Location = New Point(8, (i * HealthCtl.Height) + 8)

    which if i am thinkin correctly will move the control down 8 pixels under the one before it. It might take a little playing with though I get confused when it comes to logic since I lack quite a bit of that
    Last edited by Tool; Dec 8th, 2004 at 09:05 AM.

  3. #3
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: dynamicly add my custom control

    Once you have dynamically created the control, you have to add it to the controls collection of the container (form, pane, pic box, etc) in order for it to work.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

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