oh yeah. lol forgot to include. its for the form iteself. say maybe a button that lets user browse for a .jpeg file and then set it as that form's background. Tharoux: tried googlling it but couldn't find it.
well the second Yesterday, it was the first. Code (Text): Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ofd As New OpenFileDialog ofd.ShowDialog() If DialogResult = Windows.Forms.DialogResult.OK AndAlso ofd.FileName <> "" Then Try Me.BackgroundImage = Image.FromFile(ofd.FileName) Me.BackgroundImageLayout = ImageLayout.Stretch Catch ex As Exception MessageBox.Show(Err.Description) End Try End If End Sub
You said that you wanted image files? Code (Text): Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim ofd As New OpenFileDialog With ofd .CheckFileExists = True .Filter = "Image Files (*.bmp, *.jpg, *.png, *.gif)|*.bmp;*.jpg;*.png;*.gif" .Title = "Select an Image" .ShowDialog() End With If DialogResult = Windows.Forms.DialogResult.OK AndAlso ofd.FileName <> "" Then Try If File.Exists(ofd.FileName) Then Me.BackgroundImage = Image.FromFile(ofd.FileName) Me.BackgroundImageLayout = ImageLayout.Stretch Else MsgBox("The selected file does not exist.") Exit Sub End If Catch ex As Exception MsgBox(ex.Message) Debug.Print(ex.Message) End Try End If End Sub
lol i dunno why but when i google that exact same thing i can't find it. my 2nd is VB Helper: HowTo: The let user drag an image in VB .NET tried the given one but nothing comes out. no errors and the form's background doesn't change. i tried changing extension of my image file from jpeg to png and bitmap but nothing works.
Singapore, what do you mean? I don't exactly understand (PM?). But if you are looking for allowing the user to Drag-and-Drop the picture -- you should try enabling AllowDrop for your form. And then, have a sub that handles it.
thanks for the help ppl. i managed to solve it by doing this Code (Text): Dim ofd As New OpenFileDialog With ofd .CheckFileExists = True .Filter = "Image Files (*.bmp, *.jpg, *.png, *.gif)|*.bmp;*.jpg;*.png;*.gif" .Title = "Select an Image" .ShowDialog() End With Me.BackgroundImage = New Bitmap(ofd.FileName) Me.BackgroundImageLayout = ImageLayout.Stretch Refresh()