08-12-2010, 02:20 PM
Make a new project called 'Photo Viewer' .
Then add a 'OpenFileDialog' .
This is how it should look like :
Now dubble click your form and add this code :
Explaintion
This is a point where you can go back . By using 'Goto [name]' .
This is a Try . I try something and when it found a problem it going to ex .
This is our title of our OpenFileDialog .
This sets a Name in the Textbox of our FileDialog .
The filter says wich formats (example .exe) can be used . Like you see I have set it to everything .
This opens our FileDialog .
This set the background of our form to the chosen file in FileDialog .
The name of our form is the same as the item we selected .
This makes a new variable called 'w' as a integer . The value is the same as the width of our backgroundimage we chosen .
This makes a new variable called 'h' as a integer . The value is the same as the height of our backgroundimage we chosen .
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.
This happens when there is a unsuppored format chosen . When a user presses OK it will goto our point Retry .
If the user doesn't press OK this will happen (else) . It will close the form . The End If end the if function .
Screenshot
This is a post to contribute to the forum , hope you like it
Then add a 'OpenFileDialog' .
This is how it should look like :
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:
Code:
Try
Catch ex As Exception
End Try
Code:
OpenFileDialog1.Title = "Chose Photo"
Code:
OpenFileDialog1.FileName = "Photo"
Code:
OpenFileDialog1.Filter = "All Photo Formats |*.*"
Code:
OpenFileDialog1.ShowDialog()
Code:
Me.BackgroundImage = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
Code:
Me.Text = OpenFileDialog1.FileName
Code:
Dim w As Integer
w = Me.BackgroundImage.Width
Code:
Dim h As Integer
h = Me.BackgroundImage.Height
Code:
Me.Size = New Size(w, h)
Code:
If MessageBox.Show("Unknow Photo Format . Chose a other photo .", "Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) = Windows.Forms.DialogResult.OK Then
GoTo Retry
Code:
Else
Me.Close()
End If
Screenshot
This is a post to contribute to the forum , hope you like it