20 | 09 | 2017

Preview DWG files using the DWGThumbnail

It is possible to preview a drawing from within a form. To do so you first have to add the AutoCad DwgThumbnail Control Module. You can do this by right clicking the toolbox and click Component.


'Select Components'

This will display the components list. Scroll down to the AutoCad DWgThumbnail Control and check it.


'Components Window'

Now a new button is added to the toolbox. Select this button to create a DwgThumbnail control.


'New DWGThumbnail button'

To test it create a Form containing a button called Button1 and a DwgThumbnail Control called DWGthumbnail1.

Add the following code to the form and test it.

{code lang:vbnet lines:false hidden:false}Private Sub Button1_Click()

Dim DwgPath As String
DwgPath = "C:\Block.dwg" 'Change Block.dwg to a existing drawing

'Check if the drawing exists
If Fileexists(DwgPath) = True Then

DwgThumbnail1.DwgFileName = DwgPath
DwgThumbnail1.Visible = True
DwgThumbnail1.BackColor = RGB(0, 0, 0)
End If
End Sub

Public Function Fileexists(Fname) As Boolean
If Left(Fname, 4) = " " Then
Fileexists = False
If Dir(Fname) <> "" Then
Fileexists = True
Fileexists = False
End If

End If
End Function{/code}

The results should look like this:


'The Result'



Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles