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


Messages In This Thread
[Tut]How to make a Photo Viewer - by .Nielz - 08-12-2010, 02:20 PM
RE: [Tut]How to make a Photo Viewer - by Fragma - 08-12-2010, 02:24 PM
RE: [Tut]How to make a Photo Viewer - by .Nielz - 08-12-2010, 02:50 PM
RE: [Tut]How to make a Photo Viewer - by Fragma - 08-12-2010, 04:17 PM
RE: [Tut]How to make a Photo Viewer - by .Nielz - 08-13-2010, 03:50 AM
RE: [Tut]How to make a Photo Viewer - by -BoodyE- - 08-14-2010, 01:19 PM
RE: [Tut]How to make a Photo Viewer - by .Nielz - 08-14-2010, 02:18 PM
RE: [Tut]How to make a Photo Viewer - by mmki - 08-18-2010, 05:39 AM
RE: [Tut]How to make a Photo Viewer - by DeFacto - 08-18-2010, 05:55 AM
RE: [Tut]How to make a Photo Viewer - by .Nielz - 08-19-2010, 09:27 AM
RE: [Tut]How to make a Photo Viewer - by dfc0570 - 08-26-2010, 05:12 AM
RE: [Tut]How to make a Photo Viewer - by .Nielz - 08-27-2010, 12:40 PM
RE: [Tut]How to make a Photo Viewer - by Deadmau5 - 08-27-2010, 01:36 PM
RE: [Tut]How to make a Photo Viewer - by Xypher - 08-28-2010, 04:12 PM
RE: [Tut]How to make a Photo Viewer - by .Nielz - 08-29-2010, 02:20 AM
RE: [Tut]How to make a Photo Viewer - by Xypher - 08-29-2010, 10:49 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOURCE] Advanced Webcam Viewer TalishHF 4 3,902 08-25-2014, 01:20 AM
Last Post: dark_move
  [VB.NET] Remote desktop viewer [VB.NET] TalishHF 13 11,669 05-25-2013, 03:21 AM
Last Post: Imaking31
  [TUT] How to make a simple WebBrowser in VB 2010! [TUT] - [ Pictures] Statics 95 62,716 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,217 12-19-2011, 10:10 AM
Last Post: euverve

Forum Jump:


Users browsing this thread: 9 Guest(s)