0

I have two groups of pictures saved in two folders. I want the program to display theses pictures randomly in center of full screen form. I am trying to do this with visual basic.

Private Sub VScroll1_Change()

End Sub

Private Sub Command1_Click()
    Form2.Show
    Form1.Hide
    Timer1.Enabled = True
End Sub

Private Sub Form_Load()

End Sub

Private Sub Timer1_Timer()

   If Interval > 0 Then
       Timer1.Enabled = True
   Else
       Timer1.Enabled = False
       Form2.Hide
       End
   End If

End Sub
Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250

1 Answers1

0

If you are using Image control to display the picture and if your Image control name is "Image1", Then you can use the following to reposition your image in center every time you change the picture.

Image1.Left = (Me.ScaleWidth - Image1.Width) / 2
Image1.Top = (Me.ScaleHeight - Image1.Height) / 2

The following are added:

You have to place a FileListBox control in your form and name it f

Dim folder As String
Dim n As Integer

Private Sub Timer1_Timer()
    n = Rnd() * f.ListCount

    Image1.Picture = LoadPicture(folder & "\" & f.List(n))

    Image1.Left = (Me.ScaleWidth - Image1.Width) / 2
    Image1.Top = (Me.ScaleHeight - Image1.Height) / 2

End Sub

Private Sub Form_Load()
    folder = "D:\VLTR"

    f.Visible = False
    f.Pattern = "*.jpg"
    f.Path = folder
End Sub
Tun Zarni Kyaw
  • 2,099
  • 2
  • 21
  • 27