PDA

View Full Version : create control at run time



shamsam1
10-06-2008, 03:44 AM
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

Bob Phillips
10-06-2008, 07:58 AM
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.

shamsam1
10-06-2008, 08:13 AM
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..

Bob Phillips
10-06-2008, 02:50 PM
Then we need a lot more detail as to the process logic.

shamsam1
10-06-2008, 06:21 PM
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....

Demosthine
10-06-2008, 08:07 PM
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

shamsam1
10-07-2008, 12:29 AM
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

shamsam1
10-07-2008, 04:09 AM
instead of VB.Image how to attach external control

Demosthine
10-07-2008, 06:40 PM
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. :devil2: 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

shamsam1
10-07-2008, 07:07 PM
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...

shamsam1
10-11-2008, 03:05 AM
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

Demosthine
10-12-2008, 01:47 PM
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:


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


Any other problems?
Scott

shamsam1
10-12-2008, 09:59 PM
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

Demosthine
10-13-2008, 09:17 PM
Hey there.

You're error is arising because you are using:


DDVueControl.Open = filImage.Path


rather than


DDVueControl.Open (filImage.Path)


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

shamsam1
10-13-2008, 10:23 PM
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:dunno
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

Demosthine
10-14-2008, 05:47 PM
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

shamsam1
10-14-2008, 08:53 PM
hi scott


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

shamsam1
10-24-2008, 04:55 AM
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

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)

shamsam1
10-26-2008, 10:36 PM
hi scoot did u try this code....