Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tut]How to make a Photo Viewer
#1
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
My only goal is to help other people .
[Image: gNQgw]
How to make a Photo Viewer [HQ]
Reply
#2
Pretty cool idea I suppose. Could easily be adapted into a pretty advanced photo viewer similar to iPhoto.
Reply
#3
(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
My only goal is to help other people .
[Image: gNQgw]
How to make a Photo Viewer [HQ]
Reply
#4
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.
Reply
#5
(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
My only goal is to help other people .
[Image: gNQgw]
How to make a Photo Viewer [HQ]
Reply
#6
Nice TUT mate. First of its kind.
Reply
#7
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
SUPPORTFORUMS HELPER
Reply
#8
(08-14-2010, 01:19 PM)-BoodyE- Wrote: Nice TUT mate. First of its kind.

I like posting new things Smile
My only goal is to help other people .
[Image: gNQgw]
How to make a Photo Viewer [HQ]
Reply
#9
Heaps good bro i havent seen a tut like this in a wihle Smile
[Image: blanktemplate.png]
Reply
#10
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOURCE] Advanced Webcam Viewer TalishHF 4 3,888 08-25-2014, 01:20 AM
Last Post: dark_move
  [VB.NET] Remote desktop viewer [VB.NET] TalishHF 13 11,666 05-25-2013, 03:21 AM
Last Post: Imaking31
  [TUT] How to make a simple WebBrowser in VB 2010! [TUT] - [ Pictures] Statics 95 62,709 10-07-2012, 06:56 AM
Last Post: a99
  [TUT]Auto-Update System[TUT] HB Virus 3 2,450 01-07-2012, 02:21 PM
Last Post: Mastermrz
  [TUT]Enable and Disable TaskManger in vb.net [TUT] HB Virus 4 3,212 12-19-2011, 10:10 AM
Last Post: euverve

Forum Jump:


Users browsing this thread: 1 Guest(s)