Results 1 to 31 of 31

Thread: [SOLVED] Marquee Label

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    [SOLVED] Marquee Label

    Hey guys,
    I'm looking on how to make something like a NewsTicker.

    Imagine that I have the text "The sky is blue and today will not rain."

    And I want it to marquee something like:



    Well, let me explain, I want to always be showing something on the label, and when it ends, before ending it starts the beggining again..

    Any help would be appreciated

    Thanks
    Last edited by SirPereira; May 3rd, 2010 at 12:11 PM.

  2. #2
    Lively Member
    Join Date
    Apr 2010
    Posts
    105

    Re: Marquee Label


  3. #3
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: Marquee Label

    Utilizing a timer, play around with the .Left property of the component. Increasing it's value will move it right and decreasing it's value will move it left.

    ie.

    vb Code:
    1. Label1.Left += 1

    You'll then need to do something with the bounds of the form. I couldn't tell you what exactly, but some Google searches should yield some results.

    *On a side note... marquee text is a bit unprofessional in my opinion. Thankfully, you don't see them in websites much anymore and I don't think I've ever seen them in desktop applications.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Quote Originally Posted by weirddemon View Post
    Utilizing a timer, play around with the .Left property of the component. Increasing it's value will move it right and decreasing it's value will move it left.

    ie.

    vb Code:
    1. Label1.Left += 1

    You'll then need to do something with the bounds of the form. I couldn't tell you what exactly, but some Google searches should yield some results.

    *On a side note... marquee text is a bit unprofessional in my opinion. Thankfully, you don't see them in websites much anymore and I don't think I've ever seen them in desktop applications.
    Well, but this is not a real marquee. It is for a newsticker.

    But what you gave me to me, I already know :P As I said, I need it to be showing the beggining when it didn't achieved the end.

  5. #5
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: Marquee Label

    But what you gave me to me, I already know :P As I said, I need it to be showing the beggining when it didn't achieved the end.
    It's important to be very clear when asking your question. You can't assume we know what you know. When I read your question, it sounded like you needed to know how to accomplish the entire task. Had you said you knew how to scroll, I wouldn't have mentioned that.

    Now, I did this and found this.

    I tested out the example posted by John Anthony Oliver, and it seems to work just fine. You'll need to edit it for your needs, but it seems pretty solid.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  6. #6
    Addicted Member Mal1t1a's Avatar
    Join Date
    Mar 2008
    Posts
    157

    Re: Marquee Label

    Label1.Left += 1
    If(Label1.Left >= Me.Width)Then
    Label1.left = 0 - Label1.width
    end if

    Throw that into a timer, and it should work.

    [edit]
    Oh wait, I read the Question wrong, nevermind.
    Last edited by Mal1t1a; Apr 14th, 2010 at 01:21 PM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Quote Originally Posted by SirPereira View Post
    Well, let me explain, I want to always be showing something on the label, and when it ends, before ending it starts the beggining again..
    Sorry for correcting you, but I really said it :P

    I will try, than I will say something

    Thanks

  8. #8
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,828

    Re: Marquee Label

    That doesn't say you know how to do the scrolling. All it says is that you want to loop the text.

    Nowhere in your original post did you tell us you knew how to do the scrolling. All I'm saying is that you need to tell us, not assume, what you know or have already tried.

    Either way, the example I posted to should work and so should the other guys.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    I will see.

    Sorry for my misunderstanding then

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Well, until now I couldn't get it to work.

    Tried the codes, but didn't understood this one. What this actually does?

    http://social.msdn.microsoft.com/for...-e74187ad17fd/

    Thanks.

  11. #11
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Marquee Label

    If I understand your problem correctly, you want wrap the part of the label that has gone outside the boundaries back to the start so that you can see the entire string, instead of having to wait for it to go outside the boundary completely.

    So, for example, if you have a string "abcdefg", scrolling to the left, then you get this
    Code:
    |defg          abc|
    instead of
    Code:
    |defg               |

    To do that, you'll need to draw the string twice. Once for the 'main' string ("defg" in my example), and once for the "wrapped" string ("abc" in my example). You don't have to worry about which part of the string to draw; you just draw the entire string twice and whatever falls outside the boundaries is invisible anyway.

    You'll need to separate the two strings by some amount, and this is the tricky part that I haven't yet figured out myself (I needed this a short while ago too).

    If the length of the string is less than the width of your label, then you can separate the two strings by the width of the label. For example, if you're using DrawString to draw the string, you would have something like
    Code:
    e.Graphics.DrawString(text, Label1.Font, xPosition, 0)
    e.Graphics.DrawString(text, Label1.Font, xPosition + Label1.Width, 0)
    (text is the string and xPosition is the x-coordinate of the text, which is changed on a timer tick).

    Once the xPosition is less than minus the width of the string (use Graphics.MeasureString to determine this), you need to put it back at the end (xPosition = Label1.Width).


    But, if the string is longer than the label itself, you'll get into trouble. The two strings will start to overlap. You can just use a higher separation (instead of the label width), but then you'll get into trouble with the 'wrap around condition' (setting xPosition back to label width); you'll see a jump in the position...

    I haven't solved this yet, but I haven't really tried either so if I solve it I'll let you know.


    EDIT
    This is what I was using. Note that this is in an inherited Label, so "Me" refers to the label itself:
    vb.net Code:
    1. Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    2. * * MyBase.OnPaint(e)
    3. * *
    4. * * Dim size As SizeF = e.Graphics.MeasureString(DisplayText, Font)
    5. * * Dim w As Integer = CInt(size.Width)
    6. * * Dim h As Integer = CInt(size.Height)
    7. * *
    8.     'If the string has moved off the label, put it back at the end
    9. * * If position < -w Then
    10. * * * * position = Me.Width - w
    11. * * End If
    12. * *
    13.     'The separation between the 'real' string and the mirror string is Me.Width
    14. * * Dim mirrorPosition As Integer = position + Me.Width
    15. * *
    16.     'Drawing the two strings (note, (Me.Height - h)/2 ensures that the string is drawn in the center, vertically, instead of at the top)
    17. * * e.Graphics.DrawString(DisplayText, Font, New SolidBrush(ForeColor), position, (Me.Height - h) / 2)
    18. * * e.Graphics.DrawString(DisplayText, Font, New SolidBrush(ForeColor), mirrorPosition, (Me.Height - h) / 2)
    19. End Sub
    This still has the problem I mentioned though, it will get overlapping text if the string is too long.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Sorry, but how can I add that OnPaint event to the label?


    And, any news about solving it?

    Regards

  13. #13
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Marquee Label

    You get the OnPaint method override if you inherit the Label.

    I did solve my issue, at least half. I think it only works for scrolling to the left though, if you need it to scroll to the right you'd want to add another check in the OnPaint statement to wrap the label back to the left, once it reaches the right side.

    Anyway, my code was in C#, so I ran it through a translator quickly, so there might be some slight syntax errors:
    Code:
    Public Class ScrollLabel
    &#160; &#160; Inherits Label
    &#160; &#160; #Region "Private Fields"
    &#160; &#160; 
    &#160; &#160; Private _Timer As New Timer()
    &#160; &#160; Private _MirrorPosition As Single = 0F
    &#160; &#160; Private _Position As Single = 0F
    &#160; &#160; 
    &#160; &#160; #End Region
    &#160; &#160; 
    &#160; &#160; #Region "Properties"
    &#160; &#160; 
    &#160; &#160; ''' <summary>
    &#160; &#160; ''' The scroll speed in pixels / second. Use negative values for scrolling to the left.
    &#160; &#160; ''' </summary>
    Private _ScrollSpeed As Single
    &#160; &#160; Public Property ScrollSpeed() As Single
    &#160; &#160; &#160; &#160; Get
    &#160; &#160; &#160; &#160; &#160; &#160; Return _ScrollSpeed
    &#160; &#160; &#160; &#160; End Get
    &#160; &#160; &#160; &#160; Set(ByVal value As Single)
    &#160; &#160; &#160; &#160; &#160; &#160; _ScrollSpeed = value
    &#160; &#160; &#160; &#160; End Set
    &#160; &#160; End Property
    &#160; &#160; 
    &#160; &#160; <Browsable(False)> _
    &#160; &#160; Public Overloads Overrides Property Text() As String
    &#160; &#160; &#160; &#160; Get
    &#160; &#160; &#160; &#160; &#160; &#160; Return MyBase.Text
    &#160; &#160; &#160; &#160; End Get
    &#160; &#160; &#160; &#160; Set(ByVal value As String)
    &#160; &#160; &#160; &#160; &#160; &#160; MyBase.Text = value
    &#160; &#160; &#160; &#160; End Set
    &#160; &#160; End Property
    &#160; &#160; 
    &#160; &#160; ''' <summary>
    &#160; &#160; ''' The scrolling text.
    &#160; &#160; ''' </summary>
    Private _DisplayText As String
    &#160; &#160; Public Property DisplayText() As String
    &#160; &#160; &#160; &#160; Get
    &#160; &#160; &#160; &#160; &#160; &#160; Return _DisplayText
    &#160; &#160; &#160; &#160; End Get
    &#160; &#160; &#160; &#160; Set(ByVal value As String)
    &#160; &#160; &#160; &#160; &#160; &#160; _DisplayText = value
    &#160; &#160; &#160; &#160; End Set
    &#160; &#160; End Property
    &#160; &#160; 
    &#160; &#160; ''' <summary>
    &#160; &#160; ''' The separation between the real text and the mirror text.
    &#160; &#160; ''' </summary>
    Private _MirrorTextSeparation As Integer
    &#160; &#160; Public Property MirrorTextSeparation() As Integer
    &#160; &#160; &#160; &#160; Get
    &#160; &#160; &#160; &#160; &#160; &#160; Return _MirrorTextSeparation
    &#160; &#160; &#160; &#160; End Get
    &#160; &#160; &#160; &#160; Set(ByVal value As Integer)
    &#160; &#160; &#160; &#160; &#160; &#160; _MirrorTextSeparation = value
    &#160; &#160; &#160; &#160; End Set
    &#160; &#160; End Property
    &#160; &#160; 
    &#160; &#160; Public Enum VerticalAlignment
    &#160; &#160; &#160; &#160; Top
    &#160; &#160; &#160; &#160; Center
    &#160; &#160; &#160; &#160; Bottom
    &#160; &#160; End Enum
    &#160; &#160; Private _TextAlignment As VerticalAlignment
    &#160; &#160; Public Property TextAlignment() As VerticalAlignment
    &#160; &#160; &#160; &#160; Get
    &#160; &#160; &#160; &#160; &#160; &#160; Return _TextAlignment
    &#160; &#160; &#160; &#160; End Get
    &#160; &#160; &#160; &#160; Set(ByVal value As VerticalAlignment)
    &#160; &#160; &#160; &#160; &#160; &#160; _TextAlignment = value
    &#160; &#160; &#160; &#160; &#160; &#160; Me.Invalidate()
    &#160; &#160; &#160; &#160; End Set
    &#160; &#160; End Property
    &#160; &#160; 
    &#160; &#160; <Browsable(False)> _
    &#160; &#160; Public Overloads Overrides Property TextAlign() As System.Drawing.ContentAlignment
    &#160; &#160; &#160; &#160; Get
    &#160; &#160; &#160; &#160; &#160; &#160; Return MyBase.TextAlign
    &#160; &#160; &#160; &#160; End Get
    &#160; &#160; &#160; &#160; Set(ByVal value As System.Drawing.ContentAlignment)
    &#160; &#160; &#160; &#160; &#160; &#160; MyBase.TextAlign = value
    &#160; &#160; &#160; &#160; End Set
    &#160; &#160; End Property
    &#160; &#160; 
    &#160; &#160; #End Region
    &#160; &#160; 
    &#160; &#160; Public Sub New()
    &#160; &#160; &#160; &#160; Me.DisplayText = Me.Text
    &#160; &#160; &#160; &#160; Me.Text = [String].Empty
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; _Timer.Interval = 50
    &#160; &#160; &#160; &#160; _Timer.Enabled = True
    &#160; &#160; &#160; &#160; AddHandler _Timer.Tick, AddressOf _Timer_Tick
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; Me.AutoSize = False
    &#160; &#160; &#160; &#160; Me.TextAlignment = VerticalAlignment.Center
    &#160; &#160; &#160; &#160; Me.ScrollSpeed = -1F
    &#160; &#160; &#160; &#160; Me.MirrorTextSeparation = 0
    &#160; &#160; End Sub
    &#160; &#160; 
    &#160; &#160; Private Sub _Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
    &#160; &#160; &#160; &#160; If Not Me.DesignMode Then
    &#160; &#160; &#160; &#160; &#160; &#160; _Position += Me.ScrollSpeed
    &#160; &#160; &#160; &#160; &#160; &#160; _MirrorPosition += Me.ScrollSpeed
    &#160; &#160; &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; &#160; &#160; Me.Invalidate()
    &#160; &#160; &#160; &#160; End If
    &#160; &#160; End Sub
    &#160; &#160; 
    &#160; &#160; Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    &#160; &#160; &#160; &#160; MyBase.OnPaint(e)
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; Dim size As SizeF = e.Graphics.MeasureString(Me.DisplayText, Me.Font)
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; Dim y As Single = 0F
    &#160; &#160; &#160; &#160; Select Case Me.TextAlignment
    &#160; &#160; &#160; &#160; &#160; &#160; Case VerticalAlignment.Top
    &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; y = 0F&#160; &#160; &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; &#160; &#160; Case VerticalAlignment.Bottom
    &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; y = Me.Height - size.Height &#160; &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; &#160; &#160; Case VerticalAlignment.Center
    &#160; &#160; &#160; &#160; &#160; &#160; &#160; &#160; y = (Me.Height - size.Height) / 2F
    &#160; &#160; &#160; &#160; End Select
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; Dim sep As Single = Math.Max(Me.Width, size.Width) + Me.MirrorTextSeparation
    &#160; &#160; &#160; &#160; Dim mirrorPosition As Single = _Position + sep
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; If _Position < Me.Width - sep - size.Width Then
    &#160; &#160; &#160; &#160; &#160; &#160; _Position += sep
    &#160; &#160; &#160; &#160; End If
    &#160; &#160; &#160; &#160; 
    &#160; &#160; &#160; &#160; e.Graphics.DrawString(Me.DisplayText, Me.Font, New SolidBrush(Me.ForeColor), _Position, y)
    &#160; &#160; &#160; &#160; e.Graphics.DrawString(Me.DisplayText, Me.Font, New SolidBrush(Me.ForeColor), mirrorPosition, y)
    &#160; &#160; End Sub
    &#160; &#160; 
    End Class
    To use: simply add a new class to your project, call it ScrollLabel, paste this code into it and then Build your solution. It should now appear in your toolbox. Note that you need to use its DisplayText property to set the scrolling text, not its Text property.

  14. #14
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Marquee Label

    Hey,

    I seem to remember that this CodeBank submission might do exactly what you are after:

    http://www.vbforums.com/showthread.php?t=540356

    Gary

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Yeah, it is something like that, but smoother and words should not appear as the space appear, it needs to be already there when it shows up, and not showing suddenly.

  16. #16
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Marquee Label

    Hey,

    I am sure you could use that post as a starting point, and build on it from there.

    Gary

  17. #17

  18. #18

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    NickThissen, sorry, I jumped over ur post by distraction..

    I'm trying to set it up, but, I already have the control in my App, in the load of Form, I already set the displayText, but nothing is showing up.

    Already tried putting the code in the ScrollLabel1 Paint event and Form Paint event.

    Nothing

  19. #19
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Marquee Label

    You just need to add the code in my post to a new class and then build your solution. The ScrollLabel control will then show up in your toolbox, and you just drag it to your form and use it like any other label (except that you use the DisplayText property instead of the Text property).

  20. #20

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Even with just adding, and modifying the DisplayText, in the design, it won't show anything, and in run-time nothing shows up too..

    This is my current code:
    vb.net Code:
    1. Imports System.ComponentModel
    2.  
    3. Public Class ScrollLabel
    4.     Inherits Label
    5. #Region "Private Fields"
    6.  
    7.     Private _Timer As New Timer()
    8.     Private _MirrorPosition As Single = 0.0F
    9.     Private _Position As Single = 0.0F
    10.  
    11. #End Region
    12.  
    13. #Region "Properties"
    14.  
    15.     ''' <summary>
    16.     ''' The scroll speed in pixels / second. Use negative values for scrolling to the left.
    17.     ''' </summary>
    18.     Private _ScrollSpeed As Single
    19.     Public Property ScrollSpeed() As Single
    20.         Get
    21.             Return _ScrollSpeed
    22.         End Get
    23.         Set(ByVal value As Single)
    24.             _ScrollSpeed = value
    25.         End Set
    26.     End Property
    27.  
    28.     <Browsable(False)> _
    29.     Public Overloads Overrides Property Text() As String
    30.         Get
    31.             Return MyBase.Text
    32.         End Get
    33.         Set(ByVal value As String)
    34.             MyBase.Text = value
    35.         End Set
    36.     End Property
    37.  
    38.     ''' <summary>
    39.     ''' The scrolling text.
    40.     ''' </summary>
    41.     Private _DisplayText As String
    42.     Public Property DisplayText() As String
    43.         Get
    44.             Return _DisplayText
    45.         End Get
    46.         Set(ByVal value As String)
    47.             _DisplayText = value
    48.         End Set
    49.     End Property
    50.  
    51.     ''' <summary>
    52.     ''' The separation between the real text and the mirror text.
    53.     ''' </summary>
    54.     Private _MirrorTextSeparation As Integer
    55.     Public Property MirrorTextSeparation() As Integer
    56.         Get
    57.             Return _MirrorTextSeparation
    58.         End Get
    59.         Set(ByVal value As Integer)
    60.             _MirrorTextSeparation = value
    61.         End Set
    62.     End Property
    63.  
    64.     Public Enum VerticalAlignment
    65.         Top
    66.         Center
    67.         Bottom
    68.     End Enum
    69.     Private _TextAlignment As VerticalAlignment
    70.     Public Property TextAlignment() As VerticalAlignment
    71.         Get
    72.             Return _TextAlignment
    73.         End Get
    74.         Set(ByVal value As VerticalAlignment)
    75.             _TextAlignment = value
    76.             Me.Invalidate()
    77.         End Set
    78.     End Property
    79.  
    80.     <Browsable(False)> _
    81.     Public Overloads Overrides Property TextAlign() As System.Drawing.ContentAlignment
    82.         Get
    83.             Return MyBase.TextAlign
    84.         End Get
    85.         Set(ByVal value As System.Drawing.ContentAlignment)
    86.             MyBase.TextAlign = value
    87.         End Set
    88.     End Property
    89.  
    90. #End Region
    91.  
    92.     Public Sub New()
    93.         Me.DisplayText = Me.Text
    94.         Me.Text = [String].Empty
    95.  
    96.         _Timer.Interval = 50
    97.         _Timer.Enabled = True
    98.         AddHandler _Timer.Tick, AddressOf _Timer_Tick
    99.  
    100.         Me.AutoSize = False
    101.         Me.TextAlignment = VerticalAlignment.Center
    102.         Me.ScrollSpeed = -1.0F
    103.         Me.MirrorTextSeparation = 0
    104.     End Sub
    105.  
    106.     Private Sub _Timer_Tick(ByVal sender As Object, ByVal e As EventArgs)
    107.         If Not Me.DesignMode Then
    108.             _Position += Me.ScrollSpeed
    109.             _MirrorPosition += Me.ScrollSpeed
    110.  
    111.             Me.Invalidate()
    112.         End If
    113.     End Sub
    114.  
    115.     Protected Overloads Overrides Sub OnPaint(ByVal e As PaintEventArgs)
    116.         MyBase.OnPaint(e)
    117.  
    118.         Dim size As SizeF = e.Graphics.MeasureString(Me.DisplayText, Me.Font)
    119.  
    120.         Dim y As Single = 0.0F
    121.         Select Case Me.TextAlignment
    122.             Case VerticalAlignment.Top
    123.                 y = 0.0F
    124.             Case VerticalAlignment.Bottom
    125.                 y = Me.Height - size.Height
    126.             Case VerticalAlignment.Center
    127.                 y = (Me.Height - size.Height) / 2.0F
    128.         End Select
    129.  
    130.         Dim sep As Single = Math.Max(Me.Width, size.Width) + Me.MirrorTextSeparation
    131.         Dim mirrorPosition As Single = _Position + sep
    132.  
    133.         If _Position < Me.Width - sep - size.Width Then
    134.             _Position += sep
    135.         End If
    136.  
    137.         e.Graphics.DrawString(Me.DisplayText, Me.Font, New SolidBrush(Me.ForeColor), _Position, y)
    138.         e.Graphics.DrawString(Me.DisplayText, Me.Font, New SolidBrush(Me.ForeColor), mirrorPosition, y)
    139.     End Sub
    140.  
    141. End Class

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Anyone ?

  22. #22

  23. #23
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Marquee Label

    Hey,

    Can you provide some details as to exactly why it isn't working for you. I think this is one of those situations where the requirements haven't been correctly explained/uinderstood.

    Perhaps some screenshots will help.

    Gary

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Well, it just don't show nothing at all..

    Just this:


    Btw, do you know how to do something but with a PictureBox control?

    Because Imagine I want to add icons before the label. How could I do that and make everything scroll?

    Thanks.
    Last edited by SirPereira; May 3rd, 2010 at 11:10 AM.

  25. #25
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Marquee Label

    Ah, AutoSize, set it to false
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All Threads • Colors ComboBox • Fading & Gradient Form • MoveItemListBox/MoveItemListView • MultilineListBox • MenuButton • ToolStripCheckBox • Start with Windows

  26. #26

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    Thank you . Finally got it working.

    And what about moving labels with images, whatever?

  27. #27
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Marquee Label

    Yes, the problem is the AutoSize property. I forgot about that. I am setting it in the constructor of the control but apparently this setting gets overridden or something, so that it's still False when you drag the control to the form.

    If you want to add icons, that wouldn't be too much of a problem. You don't need a picturebox for that, the same control will do just fine. The fact that it's a label isn't important at all. I was originally letting it inherit Control directly, which would work just the same, but a Control does not support transparent background colors while a Label does, so I thought a label was more appropriate. This is also the reason I'm not using the Text property; the scrolling text is painted over the actual Text of the label. I'm sure you could get around that and be able to use the actual Text property but I never intended to make this into a real control, just something I used once, so I was fine with it the way it was.

    Anyway, my point was that you can just use the same control, you'd just have to modify the OnPaint method (and add a property that accepts an Image; in fact I think a label already has an Image, no?). Besides using DrawString to draw the text, you would use DrawImage to draw the image in the text position minus the width of the image (plus some offset probably). That's all. You'd probably want to take into account the width of the image too when determining the 'mirror position' of the mirror text, otherwise the mirror text could overlap the image if it's large enough. The logic is all in the code already, you just have to add the width of the image.

  28. #28

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: Marquee Label

    So much thank you!

    Now I've got some ideas to make the label a bit better

    Thank you a lot, really.

  29. #29

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: [SOLVED] Marquee Label

    Hello again, sorry for reviving the topic, but I'm not seeing how to implement the image field in the Label... any suggestions?

  30. #30

    Thread Starter
    Lively Member
    Join Date
    Mar 2010
    Posts
    71

    Re: [SOLVED] Marquee Label

    Hello?

  31. #31
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: [SOLVED] Marquee Label

    I'm not sure what else to tell you besides what I already did. Did you try implementing it and got into some issues? If so, what issues?

    I am painting the text in the OnPaint method. Besides painting the text, you can also paint the image using e.Graphics.DrawImage.

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