|
-
Jun 20th, 2006, 08:42 AM
#1
Thread Starter
Hyperactive Member
Flickering Text
I am using a timer control to display time but and i am using it at interval = 1. However the text always flickers. Is there anyway i can stop this.
Any Ideas?
Thanks
Jenova
-
Jun 20th, 2006, 08:43 AM
#2
Re: Flickering Text
What txt and where? Also, what happens when timer fires?
-
Jun 20th, 2006, 09:08 AM
#3
Thread Starter
Hyperactive Member
Re: Flickering Text
I'm using a timer to display the time in a label. However the text in the label flickers rapidly when i set the timer interval to 1. I would like to keep the timer at interval 1 as well.
If i had to guess i would more than likely need to double buffer it. But i am not sure how to do that.
-
Jun 20th, 2006, 09:12 AM
#4
Re: Flickering Text
why do you need to display the time every millisecond? Just set the timer to 1000.
-
Jun 20th, 2006, 09:18 AM
#5
Re: Flickering Text
Try using LockWindowUpdate to prevent flickering:
VB Code:
Option Explicit
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Sub Form_Load()
Timer1.Interval = 1
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
[B]LockWindowUpdate Me.hWnd[/B]
Label1.Caption = Time
[B]LockWindowUpdate False[/B]
End Sub
-
Jun 20th, 2006, 09:19 AM
#6
Re: Flickering Text
It has no use to set a timerinterval to 1. I don't think a refresh rate lower then 30ms can be achieved with the normal timer control.
There is also no use in changing the label's caption, if the caption doesn't change.
eg
VB Code:
Private Sub Timer1_Timer()
Dim strTime As String
strTime = Format(Time, "hh:mm:ss")
If Label1.Caption <> strTime Then
Label1.Caption = strTime
End If
End Sub
-
Jun 20th, 2006, 09:27 AM
#7
Thread Starter
Hyperactive Member
Re: Flickering Text
If i set the timers interval to a second it will delay the display of the time by a second that is why i have it at one. Thank you for all of your help. But i got it.
VB Code:
Private Declare Function DrawText Lib "user32" Alias "DrawTextA" ( _
ByVal hdc As Long, _
ByVal lpStr As String, _
ByVal nCount As Long, _
lpRect As RECT, _
ByVal wFormat As Long) _
As Long
Private Declare Function SetRect Lib "user32" ( _
lpRect As RECT, _
ByVal X1 As Long, _
ByVal Y1 As Long, _
ByVal X2 As Long, _
ByVal Y2 As Long) _
As Long
Const DC_TEXT = &H8
Const BF_BOTTOM = &H8
Const BF_LEFT = &H1
Const BF_RIGHT = &H4
Const BF_TOP = &H2
Const DT_CENTER = &H1
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Paint()
Dim R As RECT
SetRect R, 0, 0, Me.ScaleWidth, 20
DrawText Me.hdc, Time, Len(Time), R, DT_CENTER
End Sub
Private Sub Timer1_Timer()
Me.Refresh
End Sub
Regards
Jenova
-
Jun 20th, 2006, 09:32 AM
#8
Re: Flickering Text
I couldn't get your code to work, but the use of API is a little over the top here. Why not just do (with AutoRedraw set to True):
VB Code:
Private Sub Timer1_Timer()
Me.Cls
Me.Print Time
End Sub
-
Jun 20th, 2006, 09:36 AM
#9
Re: Flickering Text
AutoRedraw causes flickering more often then never... Did you try using LockWindowUpdate as I suggested yet?
-
Jun 20th, 2006, 09:42 AM
#10
Thread Starter
Hyperactive Member
-
Jun 20th, 2006, 09:57 AM
#11
Re: Flickering Text
like this?
VB Code:
Private Sub Timer1_Timer()
Me.Cls
Me.ForeColor = vbRed
Me.FontBold = True
Me.Print Time
End Sub
-
Jun 20th, 2006, 10:23 AM
#12
Thread Starter
Hyperactive Member
Re: Flickering Text
Yes but when i resize the form the text has to stay in the centre of the form also the text needs to be sized at font 18. I know that is easy (Font size) but the only problem that i would face would be trying to center (by center io mean in the middle from top to bottom and left to right) the text in the middle of the form when the user tries to resize it.
That is why i chose to use a label as it may be easier. I don't know anyway apart from the API way to do this. But your example works just as good as the API example so i would rather just use that
-
Jun 20th, 2006, 10:26 AM
#13
Re: Flickering Text
VB Code:
Private Sub Timer1_Timer()
With Me
.Cls
.ForeColor = vbRed
.FontBold = True
.FontSize = 18
.CurrentX = (.ScaleWidth - .TextWidth(Time)) \ 2
.CurrentY = (.ScaleHeight - .TextHeight(Time)) \ 2
Me.Print Time
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|