Link to home
Start Free TrialLog in
Avatar of bemson
bemson

asked on

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
Avatar of gangwisch
gangwisch

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")
imagelist1.images.add(x)
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
Avatar of bemson

ASKER

to GANGWISCH

Thanks for your suggestion, today is nearly over here, so will try tomorrow am and be back in about 17 hours
Avatar of Mike Tomlinson
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.

Regards,

Idle_Mind

Public Class FullScreenImage
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        '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
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    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.SuspendLayout()
        '
        'PictureBox1
        '
        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
        '
        'Form3
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.BackColor = System.Drawing.Color.Black
        Me.ClientSize = New System.Drawing.Size(440, 400)
        Me.Controls.Add(Me.PictureBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
        Me.Name = "Form3"
        Me.Text = "Form3"
        Me.ResumeLayout(False)

    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
        Cursor.Show()
        Me.Hide()
        ' or use
        'Me.Dispose(True)
    End Sub

    Private Sub PictureBox1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseEnter
        Cursor.Hide()
    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)
        Else
            MsgBox(fullPathFileName, MsgBoxStyle.Exclamation, "File Not Found")
        End If
    End Sub

End Class
Avatar of bemson

ASKER

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
Avatar of bemson

ASKER

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
Regards
Bob
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of bemson

ASKER

Soory for delay in replying I have had a few medical issues to resolve

However;

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