Results 1 to 6 of 6

Thread: [RESOLVED] Stop Scrolling label Flicker

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Resolved [RESOLVED] Stop Scrolling label Flicker

    i have the attached project with a scrolling label and the label flickers badly. i have tried LockWindowUpdate and that may have been worse. its a label inside a picture box and the label doesnt have a hWnd so i user LockWindowUpdate(Picture1.hWnd) and it didnt work. i also tried not having the label in the picture box any ideas how i can make it stop flicking?
    Attached Files Attached Files

  2. #2
    Addicted Member Witis's Avatar
    Join Date
    Jan 2011
    Location
    VB Forums Online Freedom Mode: Operational
    Posts
    213

    Re: Stop Scrolling label Flicker

    one way, is to use 2 picture boxes and BitBlt.
    steps:
    In the timer subroutine:
    1. the first picture box has the label in it and in the timer the label is moved to the left like you already have.
    2. now use the print statement to print the text directly onto the picture box (using the position of the label as the coordinates for printing the text onto the picture box)
    3. use BitBlt to copy the picture box onto which you just printed text to the other picture box, and this will stop the flicker.
    4. Hide the picture box with the label in it (it will flicker) so that you only see smooth scrolling text in the BitBlted picture box.

    Here are the declarations and an example of using BitBlt to copy from one picture box to the other.
    Code:
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Const SRCCOPY = &HCC0020
    
    BitBlt Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture2.hDC, 0, 0, SRCCOPY
    Last edited by Witis; Mar 30th, 2012 at 09:52 PM.
    All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.

    The plural of sun is stars you Catholic turkeys.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: Stop Scrolling label Flicker

    Witis,

    thanks for the response. i tried what i think your saying and it didn't work so im not understanding this

    here is my timer1 code
    Code:
    lblTime.Caption = Time
        lblDate.Caption = Date
        
        
        
        Picture1.Print "This is an example of Marquee Scrolling Text Using A Label And A Picture Box. this is a big example to see what is going to happen when this thing is really big"
        
       BitBlt Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture5.hDC, 0, 0, SRCCOPY
        
          Label1.Move Label1.Left - 25
          
          If Label1.Left < -Label1.Width Then Label1.Left = Picture1.Width
    picture5 is the new picture box. i made the declaration too. no error just an empty picture5 with no scrolling. i have never done bitblt before. i have attached it again
    Attached Files Attached Files
    Last edited by seanwpb; Mar 30th, 2012 at 10:10 PM. Reason: typo

  4. #4
    Addicted Member Witis's Avatar
    Join Date
    Jan 2011
    Location
    VB Forums Online Freedom Mode: Operational
    Posts
    213

    Re: Stop Scrolling label Flicker

    Hi seanwpb, see the code below and the attached form which should make it clearer.

    Set timer to 10ms
    Code:
    Option Explicit
    Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    Private Const SRCCOPY = &HCC0020
    
    Private Sub Timer1_Timer()
        Label1.Move Label1.Left - 20 ' move the label to the left for scrolling effect
        If Label1.Left < -Label1.Width Then Label1.Left = Picture1.Width
        Me.Picture1.CurrentY = Me.Label1.Top ' use the label coordinates to set printing position
        Me.Picture1.CurrentX = Me.Label1.Left ' use the label coordinates to set the printing position
        Me.Picture1.Print Me.Label1 ' print the label text on to the picture box
        Picture2.Cls ' clear the destination picbox
        BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, SRCCOPY ' bitblt picture1 to picture2 to remove flicker
    End Sub
    Attached Files Attached Files
    All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.

    The plural of sun is stars you Catholic turkeys.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: Stop Scrolling label Flicker

    Witis,

    thanks for the code. i see how it works now. The only issue is when you change the font size and or bold label1 in picture1 its all messed up. there appears to be two lines of text on top of each other in both picture boxes. any idea how to fix that?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: Stop Scrolling label Flicker

    ok i got it to work great. i modified your timer code by commenting out two lines and i can now change the font to a much bigger one and it looks perfect

    Witis, thanks for all your help

    Code:
    Private Sub Timer1_Timer()
        Label1.Move Label1.Left - 10 ' move the label to the left for scrolling effect
        If Label1.Left < -Label1.Width Then Label1.Left = Picture1.Width
        Me.Picture1.CurrentY = Me.Label1.Top ' use the label coordinates to set printing position
        Me.Picture1.CurrentX = Me.Label1.Left ' use the label coordinates to set the printing position
        'Me.Picture1.Print Me.Label1 ' print the label text on to the picture box
        'Picture2.Cls ' clear the destination picbox
        BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hDC, 0, 0, SRCCOPY ' bitblt picture1 to picture2 to remove flicker
    End Sub
    if anyone is interested in an easy demo see attached
    Attached Files Attached Files

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