Consulting

Results 1 to 19 of 19

Thread: create control at run time

  1. #1
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    create control at run time

    i want to create control at run time and limit the control .total i want to create 100 textbox,
    fisrt 30 text box in form 1 and next 30 in for 2 so on...

    based on total no of textbox no of form should be created accordingly
    i am looking for vb.6 code to do this
    Last edited by shamsam1; 10-06-2008 at 04:10 AM.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Creating controls at rfun time is a bad idea IMO, far better to create at design and hide/show those that you want to see.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    ya i know creating control is bad idea but its required for me.to create the control and form ..i am displaying images in thumbnails.i wll not be knowing how many images will be there so i want to create it at run time..

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Then we need a lot more detail as to the process logic.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    i know how to ceate control for single page..what i want to do is limit control for particular page then proceed to next page...if i wan to create total 100 contols in fisrt form i want to ceate 30 then next form2 30 sooo on....

  6. #6

    Unfinished, but Close

    Attached you will find a short version of a Thumbnail Viewer. I threw this together in about an hour for you. Although it is far from perfect, this should give you a very good starting place.

    Using some variables at the top of the Form's Code Module, you can define how many thumbnails you want per row and the maximum number of rows.

    Enjoy.
    Scott

  7. #7
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    from this site i am downloding ddvue.
    this will open auto cad drawings without installing auto cad.
    http://www.cadology.com/Software.asp#6
    DDVue.OCX Win32 ANSI BETA Version

    insted of images i want to laod dwg files

    i need to alter this code a bit
    If Right(filImage.Name, 3) = "jpg" Then
    '                        With frmThumbnails.Controls.Add("VB.Image", _
    '                            "imgThumbnail_" & intCurrPage & "_" & intRow & "_" & intCol)
    
    
     to
    some thing like this so that it captures dwg drawings
    
    If Right(filImage.Name, 3) = "dwg" Then
    '                        With frmThumbnails.Controls.Add("VB.ddvue", _
    '                            "imgThumbnail_" & intCurrPage & "_" & intRow & "_" & intCol)
    so bit stuck in this

  8. #8
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    instead of VB.Image how to attach external control

  9. #9

    Add 3rd Party Control

    Good Evening.

    Adding a Third-Party Control like that is slightly more difficult, primarily because you don't know the Class Name and almost nobody provides it outright because it is rarely needed by someone.

    To find out a Class Name, open up you Registry Editor (RegEdit.Exe or RegEdit32.Exe) and go to Edit | Find... In this case, I did a search for "DDVue" and it went to the Class_Root for:

    Computer\HKEY_CLASSES_ROOT\CLSID\{62274DEE-B5BF-48F8-910F-4F797CCBCD96}

    From there, you open the Key the Class and then the Key titled ProgID. You should find a "(Default)" Value that tells you the Class Name. In this case, it shows "DDVue.DDVueCtrl.1" This is the Class Name you will substitute for "VB.Image"

    From there, you are on your own because I have never done anything with CAD. But I'm very confident you'll be able to figure it out.

    Honestly, if you get stuck, let me know. I'll see what I can do to help.
    Good luck.

    And I'd be curious to see your final product. PM me when it's done if you're willing to send it.
    Scott

  10. #10
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi scott

    DDVue is used to open actocad drawings without installing autocad...

    code is already their in website..

    soon will sent u final out put....i just want to display control in thumbnail ,also like to do some paging like in once page ony 30 to 40 ddve controls to load...

  11. #11
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi

    i am able to create control now..but i am enable to assign the drawing to that control..again i am stuck.

    .create folder called image and place dwg drawings,


    this is code i am using
    Option Explicit
    
    Const intTop = 10
    Const itnLeft = 10
    Const intPerRow = 5
    Const intMaxRows = 1
    
    Const intWidth = 630
    Const intHeight = 750
    Const intSpacing = 50
    
    Private intCurrPage As Integer
    
    Private Sub Form_Load()
        intCurrPage = 1
        
        Get_Page intCurrPage
    End Sub
    
    Private Sub cmdPrevious_Click()
        intCurrPage = intCurrPage - 1
    
        Get_Page intCurrPage
    End Sub
    
    Private Sub cmdNext_Click()
        intCurrPage = intCurrPage + 1
    
        Get_Page intCurrPage
    End Sub
    
    Public Sub Get_Page(intPage As Integer)
    '    On Error Resume Next
    
        Dim ctlImage As Control
        For Each ctlImage In frmThumbnails.Controls
            If Left(ctlImage.Name, 3) = "dwg" Then
                frmThumbnails.Controls.Remove (ctlImage.Name)
            End If
        Next ctlImage
    
        Dim fsoSystem As FileSystemObject
        Dim folAppPath As Folder
        Dim folImages As Folder
        Dim folFiltered As Folder
        Dim filImage As File
    
        Dim intCount As Integer
        Dim intRows As Integer
        Dim intCols As Integer
    
        Dim intCurrPage As Integer
        Dim intRow As Integer
        Dim intCol As Integer
        
        intCurrPage = 1: intRow = 1: intCol = 1
    
        Set fsoSystem = New FileSystemObject
        Set folAppPath = fsoSystem.GetFolder(App.Path)
    
        Set folImages = folAppPath.SubFolders("Images")
    
        If Not folImages Is Nothing Then
            intCount = folImages.Files.Count
            If intCount <> 0 Then
                intRows = Int(intCount / intPerRow)
    
                For Each filImage In folImages.Files
                    If intCurrPage < intPage Then
                        ' We are not to the active page, so we will skip this image.
                    ElseIf intCurrPage = intPage Then
                        If Right(filImage.Name, 3) = "dwg" Then
                            With frmThumbnails.Controls.Add("DDVue.DDVueCtrl.1", _
                                "imgThumbnail_" & intCurrPage & "_" & intRow & "_" & intCol)
                                '.Picture = LoadPicture(filImage.Path)
                                .Left = (intWidth * intCol - 1) + (intSpacing * intCol)
                                .Top = (intHeight * intRow - 1) + (intSpacing * intRow)
                                .Height = intHeight
                                .Width = intWidth
                               ' .Stretch = True
                                .Visible = True
                            End With
                        End If
                    Else
                        Exit Sub
                    End If
    
                    If intCurrPage * intCol * intRow >= intCount Then
                        intCol = 1
                        intRow = 1
                     
                        intCurrPage = 1
                    ElseIf intCol = intPerRow And _
                       intRow < intMaxRows Then
                        intCol = 1
                        intRow = intRow + 1
                    ElseIf intCol = intPerRow And _
                       intRow = intMaxRows Then
                        intCol = 1
                        intRow = 1
                     
                        intCurrPage = intCurrPage + 1
                    Else
                        intCol = intCol + 1
                    End If
                Next filImage
            End If
        Else
            MsgBox "Sub-Folder 'Images' could not be found."
        End If
    End Sub

  12. #12

    Control Name and Open Function

    Hey There.

    On Line 37, you caught the change for the Control Name from 'img' to 'dwg'; however, you did not make the change on Line 74, where you execute the Controls.Add Function. It is still starting the Control's Name with 'img'.

    Second, to open the drawing in the newly created control, use:

    [VBA]
    If Right(filImage.Name, 3) = "dwg" Then
    With frmThumbnails.Controls.Add("DDVue.DDVueCtrl.1", _
    "dwgThumbnail_" & intCurrPage & "_" & intRow & "_" & intCol)
    .Open (filImage.Path)
    .Left = (intWidth * intCol - 1) + (intSpacing * intCol)
    .Top = (intHeight * intRow - 1) + (intSpacing * intRow)
    .Height = intHeight
    .Width = intWidth
    .Visible = True
    End With
    End If
    [/VBA]

    Any other problems?
    Scott

  13. #13
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi scott

    i am getting this run time error

    run time error 438 on this line"object does not support this property or method..

    it shows the exact path of drawing but its not loading the drawing
    .Open = (filImage.Path)
    .open property not available i have attached the jpeg picture for the reference
    Last edited by shamsam1; 10-13-2008 at 04:47 AM.

  14. #14

    Exclamation .Open Function, Not Method

    Hey there.

    You're error is arising because you are using:

    [VBA]
    DDVueControl.Open = filImage.Path
    [/VBA]

    rather than

    [VBA]
    DDVueControl.Open (filImage.Path)
    [/VBA]

    Remove the equal sign from you statement.

    Second, unless you are using a different version of the Control than from what is on the website, the code I sent you works perfectly. I am actually running the set of code that I posted and took the snippet directly from the project.

    In your screenshot, it does not show .Open in the list because you are not far enough down. In the list in your screenshot, the bottom item is .OLEDragConstants, which alphabetically comes before .Open. It should be farther down the list.

    Hope this helps clarify things.
    Scott

  15. #15
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi scoot

    i agree with you...

    if i am using picture box control at run time then .Open filImage.Path works perfectly
    but this external ddvue control added at run time
    .Open filImage.Path don't seems to work
    i have tried both .Open (filImage.Path) and .Open =(filImage.Path) it dotn work it gives run time error..


    if i add control fist only in form then run
    DDVue1.Open "C:\Images\100.dwg" it works perfectly
    Last edited by shamsam1; 10-13-2008 at 11:10 PM.

  16. #16

    Unused ActiveX Controls

    Top 'o the Evening to Ya.

    As I said, the update for the example is coded to work perfectly and is fully functional when I posted it. The only other thing I can think of is that you are having Visual Basic remove the data for unused ActiveX Controls.

    Depending on which build and installation you have of Visual Basic (or Visual Studio), there is a Project-specific option that can be enabled that will remove all traces of unused ActiveX Controls. This helps keeps the references down, the software package smaller, and minimizes the number of supporting controls you have to send to the end user.

    To check this:
    From the Project Explorer window (Ctrl + R), right click on the name of the project. In the example I posted, it will read ThumbnailViewer (ThumbnailViewer.vbp).
    Select ThumbnailViewer Properties...
    Click the Make tab.
    At the bottom of the Tab Control, you'll see an option for Remove information about unused ActiveX Controls. Make sure this box is NOT checked.
    Click OK and run your project again.

    If you prefer not leaving traces of all of the unused controls, add one instance of DDVue to your form, title it ddvUnused, and set it's visible property to False.

    Any other problems, let me know.
    Scott

  17. #17
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    Smile

    hi scott


    now the code is working....thanks a lot scoot......

  18. #18
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location

    display png images in pitcture /image box as thubmnail

    hi scoot i need some modification in the coding.
    with this code u can make image/picture box to display png images..in vb.6

    i am attaching the code ..i want to include this in thumbnail viewer code....

    so tha ti can display png images as thumbnail
    [vba]
    With frmThumbnails.Controls.Add("VB.Image", _
    "imgThumbnail_" & intCurrPage & "_" & intRow & "_" & intCol)
    ' .Picture = LoadPicture(filImage.Path)
    .PngImageLoad = LoadPicture(filImage.Path)
    ' .PngPictureLoad LoadPicture(filImage.Path)
    ' .PngImageLoad LoadPicture(filImage.Path)
    [/vba]

  19. #19
    VBAX Contributor
    Joined
    May 2008
    Location
    bangalore
    Posts
    199
    Location
    hi scoot did u try this code....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •