Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what's problem whit this code? it seem's uses much memory resource. because when it runs for second time , the open file dialog does not work properly.please help me.thanks in advance.
 Try

    If OpenFD.ShowDialog = Windows.Forms.DialogResult.OK Then
        PictureBox3.Image = Image.FromFile(OpenFD.FileName)

        Dim NewSize As New Size(800, 600)
        ResizedImage = New Bitmap(PictureBox3.Image, NewSize)
        PictureBox3.Image = ResizedImage
        PictureBox3.BackgroundImageLayout = ImageLayout.Stretch
    End If

    If PictureBox3.Image Is Nothing Then
        Exit Sub
    End If

    Dim i As Integer = Me.Panel2.Controls.Count - 1
    Dim x1 As Integer
    Dim y1 As Integer
    If i = -1 Then
        x1 = Panel2.Location.X + 10
        y1 = Panel2.Location.Y + 10
    Else
        x1 = Panel2.Controls(i).Location.X + 110
        y1 = Panel2.Controls(i).Location.Y
    End If

    If x1 < Panel2.Width - 50 Then
        x1 = Panel2.Location.X + 10
        y1 = Panel2.Controls(i).Location.Y + 110
    End If
    Dim ctlLocation As New Point(x1, y1)
    Dim ctrl As New PictureBox
    ctrl.Image = PictureBox3.Image
    ctrl.Location = ctlLocation
    ctrl.Size = New Size(100, 100)
    ctrl.SizeMode = PictureBoxSizeMode.StretchImage
    ctrl.BorderStyle = BorderStyle.FixedSingle
    Me.Panel2.Controls.Add(ctrl)
    PictureBox3.Image = Nothing

    AddHandler ctrl.Click, AddressOf ClickHandler1
Catch ex As Exception
    MsgBox(ex.Message, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "بروز خطا،لطفا دوباه سعی کنید")
End Try
Posted
Updated 12-Jun-13 8:45am
v2
Comments
Ron Beyer 12-Jun-13 14:34pm    
How much memory is "too much"? What do you mean "runs for a second time", do you mean running the program again, or going into this routine again?

1 solution

How many images are you putting through this code?? There is nothing wrong with the code that would cause this error, but if you were putting a couple hundred images through it, it appears to create a new PictureBox control for every image. This will cause you severe problems as you cannot have an unlimited number of controls on a form and it will consume a large amount of memory.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900