Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello everyone,

I'm creating my first User Control, an Image Viewer. I have a property Image (String), this works fine but not user friendly. You need to key the whole path or copy and paste the path. Can someone suggest me a code that browse all images file as a property.
VB
Property Image() As String
    Get
        Return ImgViewer.ImagePath
    End Get
    Set(ByVal value As String)
        ImgViewer.ImagePath = value
        If IO.File.Exists(ImgViewer.ImagePath) Then
            ImgViewer.Bmp = New Bitmap(ImgViewer.ImagePath)
            ImgViewer.TotalPage = ImgViewer.Bmp.GetFrameCount(Imaging.FrameDimension.Page)
            ImgViewer.CurrentPage = 1
            ImgViewer.Bmp.SelectActiveFrame(Imaging.FrameDimension.Page, ImgViewer.CurrentPage - 1)
            PictureBox1.Image = ImgViewer.Bmp
            ImgViewer.Width = ImgViewer.Bmp.Width
            ImgViewer.Height = ImgViewer.Bmp.Height
            PictureBox1.Width = ImgViewer.Width
            PictureBox1.Height = ImgViewer.Height
            ImgViewer.Rotate = Rotation.Rotate0
            ImgViewer.Fit = ZoomFit.None
            ImgViewer.Zoom = 0
            ImgViewer.Percent = 1.0
            ImgViewer.Invert = False
            PercentW = (ImgViewer.Width * 0.01)
            PercentH = (ImgViewer.Height * 0.01)
        End If
    End Set
End Property
Posted
Updated 20-Jan-14 22:54pm
v2

See OpenFileDialog[^] example on MSDN.

You should specify the Filter property to allow select image files only.

In your case you may use the FileNames property to get the selected file names.
 
Share this answer
 
v2
Comments
hansoctantan 21-Jan-14 6:06am    
OpenFileDialog is a control, don't know how to put that in a property
Sergey Vaselenko 21-Jan-14 6:23am    
I think you would create the function that allow users to select images.
Call this function on the click event and save the selected files in the property.
The property itself is not good place for UI actions and long time operations.
Sergey Vaselenko 21-Jan-14 6:26am    
Do you require an image file list in the specified path only?
hansoctantan 21-Jan-14 6:36am    
What I'm thinking is in Image Property there's a button same as selecting a picture in PictureBox
Sergey Vaselenko 21-Jan-14 6:53am    
If you need to allow user to select files, use OpenFileDialog.
If you need to get image files in the path, use DirectoryInfo.
If you need to get image properties when user selects an image in your control, you may set the file name in the property 'Image' and calculate them using your code.
Solve it
Added code to Property and Reference System.Design
VB
Imports System.ComponentModel

<EditorAttribute(GetType(System.Windows.Forms.Design.FileNameEditor), GetType(System.Drawing.Design.UITypeEditor)), Browsable(True), Category("Image Details"), RefreshProperties(RefreshProperties.All)> _
Property Image() As String
    Get
        Return Path
    End Get
    Set(ByVal value As String)
        Path = value 
    End Set
End Property
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900