Support Forums
[Tut]How to make a Photo Viewer - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Visual Basic and the .NET Framework (https://www.supportforums.net/forumdisplay.php?fid=19)
+---- Thread: [Tut]How to make a Photo Viewer (/showthread.php?tid=11203)

Pages: 1 2


[Tut]How to make a Photo Viewer - .Nielz - 08-12-2010

Make a new project called 'Photo Viewer' .
Then add a 'OpenFileDialog' .
This is how it should look like :
[Image: knipselb.jpg]

Now dubble click your form and add this code :
Code:
Retry:
        Try
            OpenFileDialog1.Title = "Chose Photo"
            OpenFileDialog1.FileName = "Photo"
            OpenFileDialog1.Filter = "All Photo Formats |*.*"
            OpenFileDialog1.ShowDialog()
            Me.BackgroundImage = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)

            Dim w As Integer
            w = Me.BackgroundImage.Width
            Dim h As Integer
            h = Me.BackgroundImage.Height
            Me.Size = New Size(w, h)

        Catch ex As Exception
            If MessageBox.Show("Unknow Photo Format . Chose a other photo .", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK Then
                GoTo Retry
            Else
                Me.Close()
            End If
        End Try

Explaintion

Code:
Retry:
This is a point where you can go back . By using 'Goto [name]' .

Code:
Try
Catch ex As Exception
End Try
This is a Try . I try something and when it found a problem it going to ex .
Code:
OpenFileDialog1.Title = "Chose Photo"
This is our title of our OpenFileDialog .

Code:
OpenFileDialog1.FileName = "Photo"
This sets a Name in the Textbox of our FileDialog .

Code:
OpenFileDialog1.Filter = "All Photo Formats |*.*"
The filter says wich formats (example .exe) can be used . Like you see I have set it to everything .

Code:
OpenFileDialog1.ShowDialog()
This opens our FileDialog .

Code:
Me.BackgroundImage = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
This set the background of our form to the chosen file in FileDialog .

Code:
Me.Text = OpenFileDialog1.FileName
The name of our form is the same as the item we selected .

Code:
Dim w As Integer
w = Me.BackgroundImage.Width
This makes a new variable called 'w' as a integer . The value is the same as the width of our backgroundimage we chosen .

Code:
Dim h As Integer
h = Me.BackgroundImage.Height
This makes a new variable called 'h' as a integer . The value is the same as the height of our backgroundimage we chosen .

Code:
Me.Size = New Size(w, h)
This changes the size of our form . The width is the same as our variable w and the height is the same as our variable h.

Code:
If MessageBox.Show("Unknow Photo Format . Chose a other photo .", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK Then
GoTo Retry
This happens when there is a unsuppored format chosen . When a user presses OK it will goto our point Retry .

Code:
Else
Me.Close()
End If
If the user doesn't press OK this will happen (else) . It will close the form . The End If end the if function .

Screenshot

[Image: knipseln.jpg]

This is a post to contribute to the forum , hope you like it Smile


RE: [Tut]How to make a Photo Viewer - Fragma - 08-12-2010

Pretty cool idea I suppose. Could easily be adapted into a pretty advanced photo viewer similar to iPhoto.


RE: [Tut]How to make a Photo Viewer - .Nielz - 08-12-2010

(08-12-2010, 02:24 PM)Fragma Wrote: Pretty cool idea I suppose. Could easily be adapted into a pretty advanced photo viewer similar to iPhoto.

I have seen already a bug , the picute isn't showed full because of the things on around the photo . But it's a basics's I guess Smile


RE: [Tut]How to make a Photo Viewer - Fragma - 08-12-2010

Yes it is only basic. Once my laptop is working I think I might start an advanced photo viewer. Credits to you for the idea lol.


RE: [Tut]How to make a Photo Viewer - .Nielz - 08-13-2010

(08-12-2010, 04:17 PM)Fragma Wrote: Yes it is only basic. Once my laptop is working I think I might start an advanced photo viewer. Credits to you for the idea lol.

Thanks and sure you can use the source code . It's a bit basic's , that's becaue I'm not that good at NET Smile


RE: [Tut]How to make a Photo Viewer - -BoodyE- - 08-14-2010

Nice TUT mate. First of its kind.


RE: [Tut]How to make a Photo Viewer - XACTLYSIN - 08-14-2010

Thats nice of you to post this up. Thanks ill make my own in a bit, and try to use it. Ill see if it is really nice. Thank you anyways


RE: [Tut]How to make a Photo Viewer - .Nielz - 08-14-2010

(08-14-2010, 01:19 PM)-BoodyE- Wrote: Nice TUT mate. First of its kind.

I like posting new things Smile


RE: [Tut]How to make a Photo Viewer - mmki - 08-18-2010

Heaps good bro i havent seen a tut like this in a wihle Smile


RE: [Tut]How to make a Photo Viewer - DeFacto - 08-18-2010

It's great tutorial, thanks for share.
I will try it.
And I will try to make it more advanced. Big Grin
Keep up good work. Oui