[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

Synchronizing txt box & picture box 4 slide show & speeding up changing from 1 pb 2 another

I have an app that basically is a slide show, it works, however:

I have 2 form versions, one with group boxes & one with tabs

Because it takes time to load jpg to picture boxes I have 2 group boxes or 2 tab with picture boxes, whilst one is being viewed, the other is being loaded with 2nd picture, also the photo caption is either in a label or group box text.

when I set the slide show going, I get text appearing for the second picture before the last picture has been replaced by the 2nd picture.

What I want is a synchronised text with the picture & a snappy exchange from one picture box to the next.

ie: show picture & text together at the same time & switch from one group box or tab to another at the time the event is fired (sometimes it may be activated by a click event & it does not respond fast enough)

It worked fine in vb6 but trying numerous options in net, have eluded me so far.

Also after showing about 10 pictures, it just seems to get slower & slower.

Any help is much appreciated
  • 4
  • 2
  • 2
1 Solution
the best way to pre-load these images is to use an imagelist

you should do this at runtime in form_load
dim x as new bitmap("c:\filepath")
then when it becomes time to viewing the image you can do
picturebox1.picture=imagelist1.list(pictureindex) 'it may be .listimages

this will be good for your slideshow because you can just make a global variable with dim numpictures as integer
and then increment it when the user clicks for next picture make sure you set the index back to 0 when it equals numpictures-1
bemsonAuthor Commented:

Thanks for your suggestion, today is nearly over here, so will try tomorrow am and be back in about 17 hours
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is I what use to display images.  The form displays an image in fullscreen mode and scales the image to fit the screen while preserving the images aspect ratio.

You could use two of these forms and then toggle between them from your slideshow code using the .Show() method.



Public Class FullScreenImage
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.PictureBox1.Location = New System.Drawing.Point(192, 168)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(50, 50)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.CenterImage
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(440, 400)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "Form3"
        Me.Text = "Form3"

    End Sub

#End Region

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim sc As Rectangle = Screen.PrimaryScreen.Bounds()
        Me.Left = 0
        Me.Top = 0
        Me.Width = sc.Width
        Me.Height = sc.Height
    End Sub

    Private Sub PictureBox1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
        ' or use
    End Sub

    Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
    End Sub

    Public Sub updateImage(ByVal fullPathFileName As String)
        Dim sc As Rectangle = Screen.PrimaryScreen.Bounds()
        Dim i As Image
        Dim ratio As Double
        Dim s As Size

        PictureBox1.Left = 0
        PictureBox1.Top = 0
        PictureBox1.Width = sc.Width
        PictureBox1.Height = sc.Height
        If Dir(fullPathFileName) <> "" Then
            i = Image.FromFile(fullPathFileName)
            ratio = i.Height / i.Width
            s.Width = PictureBox1.Width
            s.Height = s.Width * ratio
            If s.Height > PictureBox1.Height Then
                ratio = PictureBox1.Height / s.Height
                s.Width = s.Width * ratio
                s.Height = s.Height * ratio
            End If
            PictureBox1.Image = New Bitmap(i, s)
            MsgBox(fullPathFileName, MsgBoxStyle.Exclamation, "File Not Found")
        End If
    End Sub

End Class
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

bemsonAuthor Commented:
For Gangwisch & idle_mind

I have spent last 2 hours trying to use imagelist, without much success, image size is the problem at the moment.

I have been trying to adapt the help example for imagelist class, but keep running into problems I don't understand.

This app which is more than just a slide show has taken me over 2 years on & off to develop, starting in vb6.

For Idle_mind
thanks for your suggestion, some of the features you are using are foreign to me but will have a go.

at present I have to go out for 4 hours, will try to set up your suggestion then, but I expect it will take me a while, so probably be back in 24hrs
bemsonAuthor Commented:
After another 2 hours of searching help & trying to use your suggestions:

for gangwisch

I have exhausted my options with an imagelist for the following reasons
1. after loading 79 out of 160 pictures, I run out of memory
2. if I restrict it to say 10 then I have problems setting picturebox size from the image list
3. for whatever reason, when I do get an image in picturebox it is blurred ( and size is wrong)

for idle_mind

your suggestion is probably a solution to my problem, however your code example has routines that are foreign to me, so my programming expertise is way below yours.

I don't expect you to further elaborate to help me understand something I have not learn't yet.

However, perhaps you could explain how to modify the code using designer & not code editor, as I have looked everywhere for an option to modify using the designer.

As tomorrow is a work day & I am working on this project at home, I will endeavour to further explore your suggestion as time permits during the week at home.

Any progress & I will get back to you

Thanks to both for suggestions so far
Mike TomlinsonMiddle School Assistant TeacherCommented:
All of the code between this line,

    #Region " Windows Form Designer generated code "

and this line,

    #End Region

is generated automatically by the IDE when you drag controls onto the form and change properties about them.  You should not change things in there manually.  By cutting and pasting all of the code above into a new form, over all existing code on the form, you will get the same layout and property settings as I have them.

For instance, if you and a new form to a project, it will have something like this in it:

-   Public Class Form3
        Inherits System.Windows.Forms.Form

+      Windows Form Designer generated code

    End Class

If you select all of that code and paste the code I gave over it, then you have the exact same layout as I did.  Once you have pasted the code, you can hit the "-" symbol next to #Region " Windows Form Designer generated code " line and not worry about that code section anymore as it will get changed by the IDE as you work with the form in the designer.

Here is a small example of how to use the form.  The main form has a Button and an OpenFileDialog control on it.  Obviously you wouldn't use a file dialog box in your app, it's just an easy way to get a valid image file name.

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim result As DialogResult
        result = OpenFileDialog1.ShowDialog
        If result = DialogResult.OK Then
            Dim fs As New FullScreenImage
        End If

    End Sub

Let me know how I can be of further assistance.

Here is my best advice:

You need to keep about 5 images in that imagelist at a time you can remove the last one by using the remove method(index) this will save on memory
bemsonAuthor Commented:
Soory for delay in replying I have had a few medical issues to resolve


for gangwisch, I have checked help for use of image list & it appears that it's intention is to tye it to say a tab on a tab control.

As I already have the images stored, it does not seem logical to store them again & retrive them from an image list rather than my array already built up

For idle-mind, I have found after much form adding & heaps of useless code, all I needed was the section for the update image. it works fine with only one picturebox on one form, I was trying to load image to a duumy picturebox, determine landscape or portrait, then adjusting pic box to suit, this is where time was lost in the display

Featured Post


Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now