Whoisit

I am following a tutorial on how to open a directory and show all the pictures inside as thumbnails. Below is the last paragraph so I thought, for my purposes, I would try to create a control so that I can use it in other programs in the future.

I have now done everything I need, what I don't know is how to make it a dll so can someone show me how I compile it to a dll please

You can use this control in any of your projects by adding the Thumbnail control source code to it. Alternatively you can create a UserControl project that contains the finished thumbnail control and compile it to a DLL. You may then either add the compiled user control to any of your projects as a reference or add it to your toolbox and use it in the Visual Studio IDE.


Thanks for looking
Graham


Re: Visual Basic Express Edition Create a UserControl

ReneeC

Sure,

Start with a new project.... and select class library as the project template. That will make a DLL for you.






Re: Visual Basic Express Edition Create a UserControl

Whoisit

Don't quite see how that will work
I am trying to make a user control,
I have found an article on MSDN 'How to make a User Control',
so I will have a read of that first and see if it helps me in what I am trying to do.
According to the article in my first post, you first make a user control then compile it to a dll.




Re: Visual Basic Express Edition Create a UserControl

Dave299

Graham

A brief synopsis:

Create a new ClassLibrary project, accepting default name (Class1)

Add a User Control (under Project menu) - giving it a suitable name.

In Solution Explorer right click on Class1.vb and delete it.

Save the project.

Add your controls and your code

To test it add a new Windows Forms project to the solution (File | Add | New Project)

In Solution Explorer right click on the new project and make it the startup project.

Add a reference to the user control (Project | Add Reference | Projects)

Build the solution and the user control should appear at the top of the toolbox.

Add the control to your new project and do whatever testing you need.

When you are happy with it select one of the files from the user control and then build the control.

The dll will appear in your debug/Release folder.





Re: Visual Basic Express Edition Create a UserControl

Whoisit

Thanks Dave,
As usual clear and understandable, will try it tonight and let you know how I get on.

Graham




Re: Visual Basic Express Edition Create a UserControl

Whoisit

Got up to this point
'Build the solution and the user control should appear at the top of the toolbox.'
all ok with control at top of toolbox.
Moved on to the next section,
'Add the control to your new project and do whatever testing you need.'and got a mega error message can be seen here
http://freespace.virgin.net/viking.rover/message.gif
sorry you have to copy and paste, insert link still not working for me.
below is the full code I'm using for the control

Imports System.Drawing
Imports System.Windows.Forms
Public Class ctlThumbs

Private strFileName As String = ""
Private
Sub DrawThumbNail()
Dim dAspectRatio As Double
Dim
bm As Bitmap
Dim iTNHeight As Integer, iTNWidth As Integer

Try
' Display the filename on the label

lblFilename.Text = IO.Path.GetFileName(strFileName)

' Check that the variable strFileName contains something
If
strFileName <> "" Then
' Load the photo into a bitmap

bm = New Bitmap(strFileName)
' Calculate the aspect ration of the image
dAspectRatio = bm.Width / bm.Height
' Calculate the width and height of the thumbnail to be created
If
dAspectRatio > 1 Then
' If the image is wider than it is tall, set it's width to be the width of the
' picturebox and calculate it's height using the aspect ratio

iTNWidth = picThumbnail.Width
iTNHeight = CInt(iTNWidth / dAspectRatio)
Else
' If the image is taller than it is wide, set it's height to be the height of the
' picturebox and calculate it's width using the aspect ratio

iTNHeight = picThumbnail.Height
iTNWidth = CInt(iTNHeight * dAspectRatio)
End If

' Check we have valid heights and widths
If
iTNHeight > 0 And iTNWidth > 0 Then
' Generate the thumbnail

picThumbnail.Image = bm.GetThumbnailImage(iTNWidth, iTNHeight, Nothing, IntPtr.Zero)
End If
' Dispose of the bitmap

bm.Dispose()
Else
Tf strFileName is empty, clear the picturebox

picThumbnail.Image = Nothing
End
If

Catch ex As Exception
MsgBox("An exception occured when trying to render the thumbnail for the image '" & _
strFileName & "' with the message:" & vbCrLf & vbCrLf & ex.ToString, _
MsgBoxStyle.Exclamation)
End Try
End
Sub

Public Property FileName() As String

Get
Return
strFileName
End Get
Set
(ByVal Value As String)
strFileName = Value
DrawThumbNail()
End Set
End
Property

Private Sub Thumbnail_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize

DrawThumbNail()
End Sub

Public Event ThumbnailMouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Public Event ThumbnailDoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
Public Event ThumbnailClick(ByVal sender As Object, ByVal e As System.EventArgs)

Private Sub Control_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblFilename.Click, picThumbnail.Click
RaiseEvent ThumbnailClick(Me, e)
End Sub

Private Sub Control_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lblFilename.DoubleClick, picThumbnail.DoubleClick
RaiseEvent ThumbnailDoubleClick(Me, e)
End Sub

Private Sub Control_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles lblFilename.MouseDown, Panel1.MouseDown
Dim eNew As System.Windows.Forms.MouseEventArgs
' Convert the sender to a Control so we can access its position
Dim
c As Control = DirectCast(sender, Control)
'Create the new MouseEventArgs

eNew = New System.Windows.Forms.MouseEventArgs(e.Button, e.Clicks, e.X + c.Top, e.Y + c.Left, e.Delta)
RaiseEvent ThumbnailMouseDown(Me, eNew)
End Sub

Public Sub New(ByVal strFN As String)
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Initialize our thumbnail control
strFileName = strFN ' assign the filename for the thumbnail
DrawThumbNail() ' draw it
End
Sub

End Class







Re: Visual Basic Express Edition Create a UserControl

nobugz

Your constructor causes this exception, the designer can't supply the "strFN" argument. If you do need a constructor, it can't take any arguments. In your case, remove it; you already have the FileName property to set the required strFileName member.





Re: Visual Basic Express Edition Create a UserControl

Dave299

God you've got to be quick round here. I was about to post the following - nice to know I'd got it right

"Hi Graham

Had a very quick look (just about to have dinner) and I think it's because you have a constructor in the control (Sub New) which takes an argument and when you drop the control onto a form that argument is not being supplied.

I'll need a little time to have a proper look at it to find a workaround. If you want to look at it yourself you need to find another way of passing in the filename for the thumbnail. Possibly just create a property for the filename which you can set from the other project."





Re: Visual Basic Express Edition Create a UserControl

Whoisit

Sorry about all this I'm trying my best to understand VB, but it seems that there is a lot of outdated tutorials out there, then each person writing one writes it in his own style, it all becomes confusing and the MSDN help files don't help, unless of course you already know a good bit about VB.
The article I'm following now is from a link in the help files.
If it helps here is the link to the article I'm following
http://www.devcity.net/Articles/219/1/article.aspx




Re: Visual Basic Express Edition Create a UserControl

nobugz

Sorry Dave, I feel like I committed an Ahmed-sin. I'll wait at least 4 hours next time...





Re: Visual Basic Express Edition Create a UserControl

Dave299

Hans - no problem at all - it was nice to know I was on the right track. A what sin

Graham

As Hans says you can't use the constructor if you want to add the control in the designer (it works ok if you add it from code) and you already have a filename property (which I hadn't seen in my quick look earlier) so just comment out all of the Sub New for now then build the control again.

You should then be able to add the thumbnail control to the form in the new project without any problem. If you also add a button and add code its click event to set the thumbcontrol filename property:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CtlThumbs1.FileName = "your path and filename"
End Sub

you should find it then works ok - well it did for me so you can't be too far from getting it going.






Re: Visual Basic Express Edition Create a UserControl

Whoisit

Thanks guys for all the help, I think I may have found another way to do it with out using a control but I'm still going to stick at as I would like to see the control working.
Will keep you updated on my progress, but for now it's goodnight.




Re: Visual Basic Express Edition Create a UserControl

Whoisit

Well here's an update, I got it to work as Dave suggested, but this only shows one Thumbnail at a time I want to be able, as the tutorial is showing, to open a directory full of images and have each one shown as a thumbnail.
I went back to the tutorial, even though I'm losing faith in it, and copied and pasted the rest of the code that shouldl make it show all files in a directory.

The problem is I get a squiggley under the word Thumbnail in this line of code,
Dim tnNewThumbnail As Thumbnail

with the message, Type 'Thumbnail' is not defined.
There are no error correction options to guide me so I'm now stuck again.
I'm thinking I need something like
Dim Thumbnail as Integer,String,Object, Image or what




Re: Visual Basic Express Edition Create a UserControl

Dave299

Graham

In the article he called his user control Thumbnail.  You have called yours ctlThumbs.  If you change all references to Thumbnail to ctlThumbs you should find it works ok.  If you do a Find and Replace make sure you have Match Whole Word ticked.

I've just quickly tried it to the end of page 5 and it works well although he does rename mnuFileBrowse mnuFileOpen at one stage but I'll leave you to spot that one.

Good luck

Dave





Re: Visual Basic Express Edition Create a UserControl

Whoisit

Still no luck, I now have squiggley under strFileName
' Create a new classlibrary1.ctlThumbs
tnNewThumbnail = New ClassLibrary1.ctlThumbs(strFileName)

With the message Too many arguments to 'Public Sub New()'

I know in response to a previous reply I deleted the Public Sub New() so why is it refering to it