Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Moving Multiple Labels

Moving Multiple Labels

Scheduled Pinned Locked Moved Visual Basic
questioncomdata-structuressecurityhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jm6k
    wrote on last edited by
    #1

    I'm trying to create an interesting opening to an encryption program that I'm writing. If anyone has seen The Matrix(Who hasn't?), I'm trying to recreate the effect of those screens that have those different characters scroll down the screen. What I've done is created 21 labels on the top of my form. I create a random number from 1 to 255 so it will be used to change the individual labels. For Example : lblLabel1.text = Chr(RandomNumber) right after this command, I move the label down by 8 pixels. For Example: lblLabel1.top = lblLabel1.top + 8 I have assigned 21 timers for 21 different labels. My question is: Is there anyway that I can use a For Next loop to scroll through each label on my form instead of making all those timers? I tried making an array before, but I'm getting an error. I made the array as a public declaration Example: Public Label(20) as Label Then, when I try to have the timer go through each one, it gives me a syntax error? What should I do? What am I doing wrong? Sorry so long! Thanks for your time;P The Jazz Master 6000 DJ Badknees Parma Grind Crew - www.geocities.com/parmagrindcrew

    D 1 Reply Last reply
    0
    • J Jm6k

      I'm trying to create an interesting opening to an encryption program that I'm writing. If anyone has seen The Matrix(Who hasn't?), I'm trying to recreate the effect of those screens that have those different characters scroll down the screen. What I've done is created 21 labels on the top of my form. I create a random number from 1 to 255 so it will be used to change the individual labels. For Example : lblLabel1.text = Chr(RandomNumber) right after this command, I move the label down by 8 pixels. For Example: lblLabel1.top = lblLabel1.top + 8 I have assigned 21 timers for 21 different labels. My question is: Is there anyway that I can use a For Next loop to scroll through each label on my form instead of making all those timers? I tried making an array before, but I'm getting an error. I made the array as a public declaration Example: Public Label(20) as Label Then, when I try to have the timer go through each one, it gives me a syntax error? What should I do? What am I doing wrong? Sorry so long! Thanks for your time;P The Jazz Master 6000 DJ Badknees Parma Grind Crew - www.geocities.com/parmagrindcrew

      D Offline
      D Offline
      dynamic
      wrote on last edited by
      #2

      Dim objLabel As Control For Each objLabel In Me.Controls If TypeOf objLabel Is Label Then MsgBox(objLabel.Name) '////do your code here for that label End If Next not sure if thats the sort of thing you are after? you could then have 1 function to loop through each label rather than 20 odd sets of timers etc... and you could use sleep function inplace of timers for that function System.Threading.Thread.Sleep(20)'/// your time where it says 20.

      switch(twinsOnWay).   {   case ("twins on the way"):     MessageBox.Show("for mr and mrs dynamic","twins on the way");   break; }

      J 1 Reply Last reply
      0
      • D dynamic

        Dim objLabel As Control For Each objLabel In Me.Controls If TypeOf objLabel Is Label Then MsgBox(objLabel.Name) '////do your code here for that label End If Next not sure if thats the sort of thing you are after? you could then have 1 function to loop through each label rather than 20 odd sets of timers etc... and you could use sleep function inplace of timers for that function System.Threading.Thread.Sleep(20)'/// your time where it says 20.

        switch(twinsOnWay).   {   case ("twins on the way"):     MessageBox.Show("for mr and mrs dynamic","twins on the way");   break; }

        J Offline
        J Offline
        Jm6k
        wrote on last edited by
        #3

        Thank You! That was the kind of for next loop I was looking for. The only thing is, I have other labels on the form that do not need to be moved down (only label1 through label21). How can I only loop through labell through label21? The Jazz Master 6000 DJ Badknees Parma Grind Crew - www.geocities.com/parmagrindcrew

        D 1 Reply Last reply
        0
        • J Jm6k

          Thank You! That was the kind of for next loop I was looking for. The only thing is, I have other labels on the form that do not need to be moved down (only label1 through label21). How can I only loop through labell through label21? The Jazz Master 6000 DJ Badknees Parma Grind Crew - www.geocities.com/parmagrindcrew

          D Offline
          D Offline
          dynamic
          wrote on last edited by
          #4

          Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim objLabel As Control For Each objLabel In Me.Controls If TypeOf objLabel Is Label Then If objLabel.Name = "Label" > "0" < "21" Then MoveLabel(objLabel) End If End If Next End Sub Public Function MoveLabel(ByVal lbl As Label) Dim i As Integer Dim j As Integer = lbl.Top For i = 1 To 60 j = j + +1 lbl.Top = j System.Threading.Thread.Sleep(20) Next End Function that moves 20 label 1 at a time in a smooth scroll , you can change the time of scroll on the sleep section.:)

          switch(twinsOnWay).
            {
            case ("twins on the way")://not long now
              MessageBox.Show("for mr and mrs dynamic","twins on the way");
            break;
          }

          J 1 Reply Last reply
          0
          • D dynamic

            Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Dim objLabel As Control For Each objLabel In Me.Controls If TypeOf objLabel Is Label Then If objLabel.Name = "Label" > "0" < "21" Then MoveLabel(objLabel) End If End If Next End Sub Public Function MoveLabel(ByVal lbl As Label) Dim i As Integer Dim j As Integer = lbl.Top For i = 1 To 60 j = j + +1 lbl.Top = j System.Threading.Thread.Sleep(20) Next End Function that moves 20 label 1 at a time in a smooth scroll , you can change the time of scroll on the sleep section.:)

            switch(twinsOnWay).
              {
              case ("twins on the way")://not long now
                MessageBox.Show("for mr and mrs dynamic","twins on the way");
              break;
            }

            J Offline
            J Offline
            Jm6k
            wrote on last edited by
            #5

            Hell Yeah! Thanks a lot for your help! I owe you one The Jazz Master 6000 DJ Badknees Parma Grind Crew - www.geocities.com/parmagrindcrew

            L 1 Reply Last reply
            0
            • J Jm6k

              Hell Yeah! Thanks a lot for your help! I owe you one The Jazz Master 6000 DJ Badknees Parma Grind Crew - www.geocities.com/parmagrindcrew

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              np glad to have helped :cool:


              Private void ExpectingTwins(string twins)
              {
              switch(twins)
              {
              Case ("twins on the way"):
              MessageBox.Show("for mr and mrs dynamic","twins on the way");
              break;
              }
              }


              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups