show picture doesnt work without msgbox
Hello,
I am making a picture viewer in vb.net
when i click a button to show images from a listview it doesnot work without the msgbox!
i included code
Thank you for thaking time to help me!!Please advice.Sub shows() Dim k, s As String Dim i, j, m As Integer<br/>''' when i use this, it doesnt work!!! 'Dim cbz As New Thread(AddressOf shows) 'cbz.Start() For i = 0 To ListView1.Items.Count - 1 'k = ListView1.Items.Item(i).Text k = ListView1.Items.Item(i).SubItems.Item(2).Text 'Dim b As String = ListView1.Items.Item(i).SubItems.Item(1).Text MessageBox.Show("ListView1.Items.Item(i).SubItems.Item(2).Text") pb1.Image = Image.FromFile(k) Thread.Sleep(3000) Next Exit Sub End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim crux As New Form crux.WindowState = FormWindowState.Maximized crux.Size = New Size(20, 20) crux.MaximizeBox = False crux.MinimizeBox = False crux.BackColor = Color.Black crux.Text = "Berchmanianum SlideShow Maker 1.0" pb1.Dock = DockStyle.Fill pb1.BackColor = Color.Black pb1.Size = New Size(30, 30) pb1.SizeMode = PictureBoxSizeMode.StretchImage pb1.BorderStyle = BorderStyle.Fixed3D crux.Controls.Add(pb1) crux.Show() Me.Hide()<br/>''' when i use this, it does not work!!!! 'Dim cbz As New Thread(AddressOf shows) 'cbz.Start() shows() End Sub<br/><br/>
With kind regards,
rocky
Réponses
- Hi rockydk,
if you put the code from Shows() in the Timer.Tick then the code ( with the for..next ) will be executed each time the Timer.Tick event is fired. So every 5 sec. your code will be executed ( the whole for..next ).
As a suggestion you can use the code below:
Dim ListViewIndex As Integer = -1 Sub shows(ByVal ListViewIndex As Integer) Dim ImageFileName As String pb1.image = Nothing ImageFileName = ListView1.Items.Item(ListViewIndex).SubItems.Item(2).Text pb1.Image = Image.FromFile(ImageFileName) End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() ListViewIndex = ListViewIndex + 1 If ListViewIndex <= ListView1.Items.Count - 1 Then shows(ListViewIndex) Timer1.Start() Else MsgBox("finished") End If End Sub
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
- Hi again,
' add this to the button ... listviewindex = -1 ' and change this: Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() listviewindex = listviewindex + 1 If listviewindex < +ListView1.Items.Count - 1 Then shows(listviewindex) Timer1.Start() Else MsgBox("De slideshow is afgelopen!") End If End Sub ' to this ( i don`t know where the plus sign is comming ): Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() listviewindex = listviewindex + 1 If listviewindex <= ListView1.Items.Count - 1 Then shows(listviewindex) Timer1.Start() Else MsgBox("De slideshow is afgelopen!") End If End Sub
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marqué comme réponseYiChun ChenMSFT, Modérateurvendredi 6 novembre 2009 02:04
- Use a timer. Load the PictureBox in the Timer.Tick event.
- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
- Hi again,
change the shows method like following:
Sub shows(ByVal ListViewIndex As Integer) Dim ImageFileName As String If pb1.Image IsNot Nothing Then pb1.Image.Dispose() End If pb1.Image = Nothing ImageFileName = ListView1.Items.Item(ListViewIndex).SubItems.Item(2).Text pb1.Image = Image.FromFile(ImageFileName) End Sub
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
Hello Heslacher,
sorry it works 100%
the problem was i had i file betrween with the .db extension, i need to load the files with only image extensions
thank you very much
regards,
rocky
- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
Toutes les réponses
- Use a timer. Load the PictureBox in the Timer.Tick event.
- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
Hello John,
Thank you for your response. Could help me on the way with a sample code, i dont know where to start.
??
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim crux As New Form
crux.WindowState = FormWindowState.Maximized
crux.Size = New Size(20, 20)
crux.MaximizeBox = False
crux.MinimizeBox = False
crux.BackColor = Color.Black
crux.Text = "Berchmanianum SlideShow Maker 1.0"
pb1.Dock = DockStyle.Fill
pb1.BackColor = Color.Black
pb1.Size = New Size(30, 30)
pb1.SizeMode = PictureBoxSizeMode.StretchImage
pb1.BorderStyle = BorderStyle.Fixed3D
crux.Controls.Add(pb1)
crux.Show()
Me.Hide()<br/>''' when i use this, it does not work!!!!
'Dim cbz As New Thread(AddressOf shows)
'cbz.Start()
''shows()
timer1.start
End Sub<br/><br/>
and the code from Shows in the timer1 tick event gets a out of memory exeption?
with regards,
rocky- Hello John
Also when i use the timer i ts not working
here
pb1.Image = Image.FromFile(k)
i get out of memory?
Please advice.
regards,
rocky - Put the following statement as the first statement in the Timer.Tick event:
Timer1.Stop
Do you still get an out of memory error? Hello John
Also when i use the timer i ts not working
here
pb1.Image = Image.FromFile(k)
i get out of memory?
Please advice.
regards,
rocky
did you set your time?
interval
Don't judge me, just Upgrade me. Thanks!- Hello John,
Yes i set the interval on 5000, 5 seconds, and when i put on the first line of the timer tick event timer.stop i get the same
but also this wont work becauase after that would come the for next code and then the timer will be stopped allready?
rehards,
rocky PictureBox is notorious for the OutOfMemory exception.
Try loading smaller images with a larger time interval. Also make sure you call Dispose on your image before loading the next one. You could also look at dynamically resizing your images if they are too big
Ganesh Ranganathan
[Please mark the post as answer if it answers your question]
blog.ganeshzone.net- Hello Ganesh,
thank you for your reply, the largest image is 791kb this isnot big, is it??
also when i use dispose i get the same
regards,
rocky - my code now still not working
please help!Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim crux As New Form crux.WindowState = FormWindowState.Maximized crux.Size = New Size(20, 20) crux.MaximizeBox = False crux.MinimizeBox = False crux.BackColor = Color.Black crux.Text = "Berchmanianum SlideShow Maker 1.0" pb1.Dock = DockStyle.Fill pb1.BackColor = Color.Black pb1.Size = New Size(30, 30) pb1.SizeMode = PictureBoxSizeMode.StretchImage pb1.BorderStyle = BorderStyle.Fixed3D crux.Controls.Add(pb1) crux.Show() Me.Hide() 'Dim cbz As New Thread(AddressOf shows) 'cbz.Start() 'shows() Timer1.Enabled = True Timer1.Start() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim k As String Dim i As Integer Timer1.Stop() For i = 0 To ListView1.Items.Count - 1 Timer1.Start() k = ListView1.Items.Item(i).SubItems.Item(2).Text pb1.Dispose() 'MessageBox.Show(ListView1.Items.Item(i).SubItems.Item(2).Text) pb1.Image = Image.FromFile(k) Next Exit Sub End Sub - Hi rockydk,
if you put the code from Shows() in the Timer.Tick then the code ( with the for..next ) will be executed each time the Timer.Tick event is fired. So every 5 sec. your code will be executed ( the whole for..next ).
As a suggestion you can use the code below:
Dim ListViewIndex As Integer = -1 Sub shows(ByVal ListViewIndex As Integer) Dim ImageFileName As String pb1.image = Nothing ImageFileName = ListView1.Items.Item(ListViewIndex).SubItems.Item(2).Text pb1.Image = Image.FromFile(ImageFileName) End Sub Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() ListViewIndex = ListViewIndex + 1 If ListViewIndex <= ListView1.Items.Count - 1 Then shows(ListViewIndex) Timer1.Start() Else MsgBox("finished") End If End Sub
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
Hello Heslacher,
thank you this works 90% but
After 5 images i get the out of memory again?
With kind regards,
rocky- Hi again,
change the shows method like following:
Sub shows(ByVal ListViewIndex As Integer) Dim ImageFileName As String If pb1.Image IsNot Nothing Then pb1.Image.Dispose() End If pb1.Image = Nothing ImageFileName = ListView1.Items.Item(ListViewIndex).SubItems.Item(2).Text pb1.Image = Image.FromFile(ImageFileName) End Sub
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
- Replace the Timer1_Tick code with:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() pb1.image = Image.FromFile(ListView1.Items(0).SubItems(2).Text) End Sub
Do you get an image without error? Hello Heslacher,
sorry it works 100%
the problem was i had i file betrween with the .db extension, i need to load the files with only image extensions
thank you very much
regards,
rocky
- Marqué comme réponseYiChun ChenMSFT, Modérateurmercredi 4 novembre 2009 08:50
- Hello Heslacher,
Thank you for your xtra reply!! great
I have one question about the crux form created after the button3 click event
when the slideshow is finished and i click the close button and i fire the button3 click event again i get the following error
cannot acces a disposed object
how to handle this
Regards,
Rocky Hi again,
where in the code do you get the exception ?
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- HI,
In the button3 click event on crux.show
regards,
rocky - Thats what i have guessed, but where exactly(wich line) is the exception thrown ?
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - Hi,
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim crux As New Form crux.WindowState = FormWindowState.Maximized crux.Size = New Size(20, 20) crux.MaximizeBox = False crux.MinimizeBox = False crux.BackColor = Color.Black crux.Text = "Berchmanianum SlideShow Maker 1.0" pb1.Dock = DockStyle.Fill pb1.BackColor = Color.Black pb1.Size = New Size(30, 30) pb1.SizeMode = PictureBoxSizeMode.StretchImage pb1.BorderStyle = BorderStyle.Fixed3D crux.Controls.Add(pb1)' crux.Show() '''on this line'' Timer1.Start() End Sub
- Hi again,
in such a case it is really hard to find the problem without the code.
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - Hi,
Here is the code. Please adjust the path to images, its hardcoded in the form load event.
The slideshow works but when you click the close button on the form crux and
you click again on slide the expeption is thrown.
I have also tried to make a second form in vs, and try to work like that, but same problem.
Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ListView1.View = View.Details ' Add a column with width 80 and left alignment ListView1.Columns.Add("Pad", 150, HorizontalAlignment.Left) ListView1.Items.Add("C:\Documents and Settings\All Users\Documenten\Mijn afbeeldingen\Voorbeelden van afbeeldingen\Blauwe heuvels.jpg") ListView1.Items.Add("C:\Documents and Settings\All Users\Documenten\Mijn afbeeldingen\Voorbeelden van afbeeldingen\Waterlelies.jpg") ListView1.Items.Add("C:\Documents and Settings\All Users\Documenten\Mijn afbeeldingen\Voorbeelden van afbeeldingen\Winter.jpg") ListView1.Items.Add("C:\Documents and Settings\All Users\Documenten\Mijn afbeeldingen\Voorbeelden van afbeeldingen\Zonsondergang.jpg") End Sub Sub shows(ByVal listviewindex As Integer) 'pb1.Image = Nothing 'imagefilename = ListView1.Items.Item(listviewindex).SubItems.Item(0).Text 'pb1.Image = Image.FromFile(imagefilename) If pb1.Image IsNot Nothing Then pb1.Image.Dispose() End If pb1.Image = Nothing ImageFileName = ListView1.Items.Item(listviewindex).SubItems.Item(0).Text pb1.Image = Image.FromFile(ImageFileName) End Sub Dim pb1 As New PictureBox Dim lbl1 As New Label Dim listviewindex As Integer = -1 Dim ImageFileName As String Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() listviewindex = listviewindex + 1 If listviewindex < +ListView1.Items.Count - 1 Then shows(listviewindex) Timer1.Start() Else MsgBox("De slideshow is afgelopen!") End If End Sub Private Sub btnSlide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSlide.Click Dim crux As New Form crux.WindowState = FormWindowState.Maximized crux.Size = New Size(20, 20) crux.MaximizeBox = True crux.MinimizeBox = True crux.BackColor = Color.Black crux.Text = "Berchmanianum SlideShow Maker 1.0" pb1.Dock = DockStyle.None pb1.BackColor = Color.Black pb1.Size = New Size(18, 18) pb1.Size = New System.Drawing.Size(1024, 652) pb1.SizeMode = PictureBoxSizeMode.StretchImage pb1.BorderStyle = BorderStyle.Fixed3D crux.Controls.Add(pb1) crux.Show() Timer1.Start() End Sub End Class
Please advice.
Regards,
Rocky - Hi again,
that has been easy.
' Change this: Dim pb1 As New PictureBox ' to this: Dim pb1 As PictureBox ' Insert this: pb1 = New PictureBox ' inside this: Private Sub btnSlide_Click.......
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/ - Hi,
Yes now it doesnt give the exeption but it gives the messagebox.
How can we let the listview begin from the first item.
Als it doesnot show the last image in the listview?
Regards,
rocky - Hi again,
' add this to the button ... listviewindex = -1 ' and change this: Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() listviewindex = listviewindex + 1 If listviewindex < +ListView1.Items.Count - 1 Then shows(listviewindex) Timer1.Start() Else MsgBox("De slideshow is afgelopen!") End If End Sub ' to this ( i don`t know where the plus sign is comming ): Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick Timer1.Stop() listviewindex = listviewindex + 1 If listviewindex <= ListView1.Items.Count - 1 Then shows(listviewindex) Timer1.Start() Else MsgBox("De slideshow is afgelopen!") End If End Sub
If you have got questions about this, just ask.
Mark the thread as answered if the answer helps you. This helps others who have the same problem !
C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/- Marqué comme réponseYiChun ChenMSFT, Modérateurvendredi 6 novembre 2009 02:04
- Hi,
thank you very much this is great!!!!!!!!
Thank you fot helping me get true this.
regards,
rocky

