在窗体的标题栏右侧嵌入一个时钟,并按12小时显示

来源:百度知道 编辑:UC知道 时间:2024/04/28 11:08:37
且无论窗体如何变化,该时钟始终紧挨标题栏窗体控制按钮。谢谢各位大佬。

在窗体上添加一个计时器,试试下面代码的效果,不知道是不是你想要的
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
Dim i As Long
Form1.FontSize = 12
i = TextWidth("A")
w = Form1.ScaleWidth - 1400 - TextWidth(Format(Time, "h:m:s AMPM"))
If w \ i > 0 Then
s = String((w \ i), " ") & Format(Time, "h:m:s AMPM")
Else
s = Format(Time, "h:m:s AMPM")
End If
Me.Caption = s
End Sub