Interacting with controls added at runtime

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ncag
    New Member
    • Jun 2006
    • 4

    Interacting with controls added at runtime

    I have created a number of picture boxes and filled them with an image at runtime. The question is "How if possible can I create a click or double click event for those picture boxes?"

    I am trying to be able to change the background from the available pictures in the picture boxes so I need a click event.


    Thank you,


    Keith Kelly
  • VBPhilly
    New Member
    • Aug 2007
    • 95

    #2
    Use WithEvents.

    Code:
    Public WithEvents MyPicControl As PictureBox
    I should ask, how are you creating them @ runtime? From an existing control?

    Comment

    • pureenhanoi
      New Member
      • Mar 2007
      • 175

      #3
      Originally posted by ncag
      I have created a number of picture boxes and filled them with an image at runtime. The question is "How if possible can I create a click or double click event for those picture boxes?"

      I am trying to be able to change the background from the available pictures in the picture boxes so I need a click event.


      Thank you,


      Keith Kelly
      Pls describe your problems more clearly

      Comment

      • ncag
        New Member
        • Jun 2006
        • 4

        #4
        First, thank you for your replys.

        Here is the code for creating the controls. Please be kind, I am not that proficient in VB but here it is.

        I basically search a folder that has the pictures and then create appropriate picture boxes and load them with the image.

        I have it in the Form_Load

        Dim ctlname as vb.picturebox
        Dim l as integer
        Dim lfilename as string, lpic as picture
        Dim pfolder as string, pextension as string, pwidth as long, pheight as long, pscalemode as long

        pfolder = app.path & "\pictures\ "
        pextenstion = "*.jpg"
        pwidth = 1000
        pheight = 1000

        getfilecount "path to pictures"

        s = 0
        l = 1000
        do while s <> x
        l = s * 1000
        Set stlname = Form1.controls. add("vb.picture box", "Pict" & s, Form1)
        ctlname.visible = true
        ctlname.width = 1000
        ctlname.move 1, ctlname.width, 1000, 1000
        s - s + 1

        with ctlname
        .borderstyle = 0
        .width = ctlname.scalex( pwidth, pscalemode, ctlname.parent. scalemode)
        .height = ctlname.scalex( pheight, pscalemode, ctlname.parent. scalemode)
        .autoredraw = true
        .scalemode = pscalemode
        end with

        lfilename = dir(pfolder & pextension)
        Do while lfilename <> ""
        set lpic = loadpicture(pfo lder & lfilename)
        ctlname.paintpi cture lpic, 0, 0, pwidth, pheight
        lfilename = Dir
        if lfilename <> "" then
        if s <> x then
        exit do
        end if
        loop

        Thanks

        Keith Kelly
        Last edited by ncag; Aug 30 '07, 02:10 AM. Reason: Not Finished

        Comment

        • SammyB
          Recognized Expert Contributor
          • Mar 2007
          • 807

          #5
          Just do it like microsoft does at http://support.microsoft.com/kb/q190670/. HTH --Sam

          Comment

          Working...