Page 1 of 2 12 LastLast
Results 1 to 40 of 60

Thread: [RESOLVED] [2005] Scrolling Label Text

  1. #1

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Resolved [RESOLVED] [2005] Scrolling Label Text

    I have been searching the form for a way to scroll text in a label control kinda like a marquee. I found the following code:

    Code:
            Static counter As Integer = 0
    
            Dim scrollingText As String = "This is some scrolling text that I want to see"
            If counter = scrollingText.Length Then counter = 0
            lblPlaying.Text = scrollingText.Substring(counter) & scrollingText & scrollingText & scrollingText
            counter += 1
    The problem I am having is this is not a clean scroll... It is scrolling character for character on the left side of the label but the right side of label is displaying word by word.

    Any idea how to fix this?

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [2005] Scrolling Label Text

    use textbox. i have seen this before.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [2005] Scrolling Label Text

    try using a textbox. set .readonly to true + .borderstyle to none

  4. #4

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [2005] Scrolling Label Text

    I was trying to stay away from a text box because I need the control to accept a transparent background.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [2005] Scrolling Label Text

    you won't get a real transparent background with either a label or a textbox

  6. #6

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [2005] Scrolling Label Text

    No that is physically moving the control on the form. I just need to move the text. Reason being is if the text is to long for the label control, I just want to scroll it.

  7. #7

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [2005] Scrolling Label Text

    That is still not clean at all. It scrolls per word, not per character.

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [2005] Scrolling Label Text

    a textbox scrolls how you want it to

  9. #9

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [2005] Scrolling Label Text

    Yeah, I could use a textbox but it does not allow the background to be transparent.

    I am NOW working on a control that will allow me to have a marquee, my math appears to be a little off.

    Can someone see if they see what is wrong?

    Attached is the solution.


    EDIT: UPDATED CONTROL BELOW
    Last edited by .NetNinja; Nov 5th, 2008 at 03:46 PM.

  10. #10

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [2005] Scrolling Label Text

    Here is my Marquee control. Glad to have this done. Hope this helps someone too.

    EDIT: UPDATED CONTROL BELOW
    Last edited by .NetNinja; Nov 5th, 2008 at 03:46 PM.

  11. #11
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Hi,

    Thanks for your control .. can you make the same control but then scroll from right to left? .. or just tell me what i should change..

    Thanks in advanced

  12. #12

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Resolved Re: [RESOLVED] [2005] Scrolling Label Text

    Here is an updated version that does scroll left to right.

    Be sure that you use true type fonts with this control. I have seen some issues with non TTFs.

    EDIT: UPDATED CONTROL BELOW
    Last edited by .NetNinja; Nov 6th, 2008 at 08:28 AM.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  13. #13
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [RESOLVED] [2005] Scrolling Label Text

    Quote Originally Posted by .NetNinja
    Here is an updated version that does scroll left to right.

    Be sure that you use true type fonts with this control. I have seen some issues with non TTFs.
    i thought it had a transparent background?

  14. #14
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    fast reply .. your original scrolled from left to right .. i need it from right to left

  15. #15

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Quote Originally Posted by Amien
    fast reply .. your original scrolled from left to right .. i need it from right to left
    Let me look into making a property for scroll direction.

    Quote Originally Posted by .paul.
    i thought it had a transparent background?
    It does have a transparent background if you set the background color to transparent.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  16. #16
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [RESOLVED] [2005] Scrolling Label Text

    thats a transparent background color. i.e. not really transparent, as i told you in post #5

  17. #17
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Quote Originally Posted by .NetNinja
    Let me look into making a property for scroll direction.
    Thanks ... not to push you or anything .. but if its not too much to ask

    and can this also be done with the control:

    i need to change the MarqueeText right after the last letter is of the screen .. i'm planning on binding Marqueetext to a dynamic xml file

  18. #18

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Well, that would take a major add-in for the control to cycle through an array or list of text you want to display. I will look into it though. Might not be to bad to manage.

    It will take me a little time also, this control was mainly written for another application I am working on, just give me a little time. Hopefully by tomorrow I will have something put together.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  19. #19
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Private Sub loadthenews()
    Dim readXML As New XmlTextReader("e:\news.xml")
    While readXML.Read()
    If readXML.NodeType = XmlNodeType.Text Then
    ScrollingMarquee1.MarqueeText += " " & readXML.Value

    End If
    End While
    End Sub

    I have this in my app to load the xml text. this loads the text on form_load..

    i need to reload the news on the moment that the text cycles .. i could build a timer to reload the text every 10 min ..

  20. #20
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    is it also possible that, if the text is gone on the right .. that the text appears letter for letter again on the left .. at this moment when the text is gone of the left .. the full text appears again in the scrollbar and then starts scrolling ..

    btw .. was this changed in the new version .. cause i thought on the old version the text appeared letter for letter of the left.

  21. #21
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    sorry for the spam...

    would i be possible to build a Thread.Sleep(3000) but that the Text keeps scrolling?

  22. #22
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [RESOLVED] [2005] Scrolling Label Text

    not on the same thread

  23. #23
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Above the marquee i have a picturebox. that picturebox has a random picture from a certain directory. i want to refresh that picturebox after a few seconds with a new random picture. this while the marquee keeps on running without delay.

  24. #24
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Do While UserWantsOut = False

    Dim Files() As String = Directory.GetFiles("C:/tmp/")
    Dim Gen = New System.Random(My.Computer.Clock.TickCount)

    Application.DoEvents()
    PictureBox2.Image = Image.FromFile(Files(Gen.Next(1, Files.Length).ToString))

    'Label1.Text = Files(Gen.Next(1, Files.Length).ToString)

    Loop

    For some reason Picturebox2 hangs after a few seconds .. while Label1 keeps on running

  25. #25
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [RESOLVED] [2005] Scrolling Label Text

    For scrolling text you may want to take a look at the link in my signature.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  26. #26
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    i solved the Thread.Sleep(3000) problem with a Timer2 .. works fine

  27. #27

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Attached is the new source code for the Marquee control. It allows you to set which direction you want the text to scroll by setting ScrollLeftToRight to True or False.

    EDIT: UPDATED CONTROL BELOW
    Last edited by .NetNinja; Nov 6th, 2008 at 01:21 PM.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  28. #28
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    works fine NetNinja .. Thanks

    can you please reponse to #22?

  29. #29

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Quote Originally Posted by Amien
    works fine NetNinja .. Thanks

    can you please reponse to #22?
    To you answer your question, if I understand correctly, it should be doing that in this version.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  30. #30
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    when the text is at the end .. the control is cleared completely .. i want to text to scroll completely of the screen .. and then the last letter of the text is of the screen .. then the text should start again on the right side...

    thanks so far btw .. great help

  31. #31

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    What size is the control on your form?
    What font are you using?

    EDIT:
    I have noticed an issue when the font size and/or name is changed. To account for this you might want to modify the calculation (y = -5 * -x) in the tmrMain_Tick subroutine. This will vary on a case by case basis. That is one of the reason I provided this in full source. If a universal solution is found I will post an update to the source.

    Note on a variations on the calculation, only the static value (-5) needs to be modified, the variables should remained untouched.
    Last edited by .NetNinja; Nov 6th, 2008 at 10:41 AM.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  32. #32
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: [RESOLVED] [2005] Scrolling Label Text

    you should write a "Direction" property in it, so it can scroll right to left as well as left to right

  33. #33
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Quote Originally Posted by .NetNinja
    What size is the control on your form?
    What font are you using?

    EDIT:
    I have noticed an issue when the font size and/or name is changed. To account for this you might want to modify the calculation (y = -5 * -x) in the tmrMain_Tick subroutine. This will vary on a case by case basis. That is one of the reason I provided this in full source. If a universal solution is found I will post an update to the source.

    Note on a variations on the calculation, only the static value (-5) needs to be modified, the variables should remained untouched.
    Thanks .. i'v solved it also by adding a few spaces to the end of ScrollingMarquee1.MarqueeText

  34. #34

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Okay the new version has a property for text direction. Also now all fonts and font sizes work. Also it will scroll like a "true" marquee, and will NOT start at the first few characters of the text.
    Attached Files Attached Files
    Last edited by .NetNinja; Nov 10th, 2008 at 11:15 AM.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  35. #35
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    tested it .. works.. again great job

  36. #36
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    "Well, that would take a major add-in for the control to cycle through an array or list of text you want to display. I will look into it though. Might not be to bad to manage."

    I'v add a timer .. that reads a xml file every x-seconds .. and then updates ScrollingMarquee1.MarqueeText. but the text is not updated and the marquee is getting really slow ..

  37. #37

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Do you have any sample code of how you are doing that?
    "Don't try to be a great man. Just be a man and let history make its own judgement."

  38. #38
    Frenzied Member obi1kenobi's Avatar
    Join Date
    Aug 2007
    Posts
    1,091

    Re: [RESOLVED] [2005] Scrolling Label Text

    Great control! I think you should post it in the CodeBank!

    @jmcilhinney: The scrolling text link in your signature is missing the C# link.
    Please rate helpful ppl's posts. It's the best 'thank you' you can give

  39. #39
    Hyperactive Member
    Join Date
    Jan 2008
    Posts
    267

    Re: [RESOLVED] [2005] Scrolling Label Text

    Code:
    Timer1.Enabled = True
    Timer1.Interval = 5000
    5000 is just for testing

    Code:
    Private Sub LoadTheNews()
            Dim readXML As New XmlTextReader("c:/tmp/news.xml")
            While readXML.Read()
                If readXML.NodeType = XmlNodeType.Text Then
                    ScrollingMarquee1.MarqueeText += " " & readXML.Value
                End If
            End While
    End Sub

    Code:
     Private Sub Timer1_Tick(ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles Timer1.Tick
         LoadTheNews()
    End Sub

  40. #40

    Thread Starter
    Hyperactive Member .NetNinja's Avatar
    Join Date
    Oct 2008
    Location
    USA
    Posts
    281

    Re: [RESOLVED] [2005] Scrolling Label Text

    Its probably getting slow because of:

    Code:
    ScrollingMarquee1.MarqueeText += " " & readXML.Value
    You are never clearing the text, so every 5 seconds the Text gets longer and longer.

    Try:
    Code:
    Private Sub LoadTheNews()
            Dim readXML As New XmlTextReader("c:/tmp/news.xml")
            ScrollingMarquee1.MarqueeText = ""
            While readXML.Read()
                If readXML.NodeType = XmlNodeType.Text Then
                    ScrollingMarquee1.MarqueeText += " " & readXML.Value
                End If
            End While
    End Sub
    ___________________________________________________________________________
    @obi1kenobi
    Quote Originally Posted by obi1kenobi
    Great control! I think you should post it in the CodeBank!
    Thanks! I probably will put it in the code bank.
    "Don't try to be a great man. Just be a man and let history make its own judgement."

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width