vb 让上下两个label 中的数字对齐
- 提问者网友:了了无期
- 2021-04-11 08:12
我想要上下对齐
用空格的话,没有“-”“.”是可以的
我想问下有解决含“-”“.”的对齐方法吗?
- 五星知识达人网友:往事隔山水
- 2021-04-11 09:03
'按","来对齐的,由于2个label的","数量可能不一样,所以都是分开处理的,数量不限按最长的分割。
Option Explicit
Private Sub Form_Activate()
Dim a, b, abmax, i
Me.Height = 3600
Me.Width = 4800
Label1.Left = 480: Label2.Left = 480
Label2.Top = 480: Label2.Top = 800
Label1.AutoSize = True
Label2.AutoSize = True
Label1.Caption = "1,1,1"
Label2.Caption = "11,-1,-0.5"
a = Split(Label1.Caption, ",")
b = Split(Label2.Caption, ",")
For i = 0 To UBound(a)
If abmax < Len(a(i)) Then abmax = Len(a(i))
Next
For i = 0 To UBound(b)
If abmax < Len(b(i)) Then abmax = Len(b(i))
Next
Label1.Caption = ""
Label2.Caption = ""
For i = 0 To UBound(a)
Label1.Caption = Label1.Caption & Space(abmax - Len(a(i))) & a(i) & ","
Next
For i = 0 To UBound(b)
Label2.Caption = Label2.Caption & Space(abmax - Len(b(i))) & b(i) & ","
Next
End Sub
- 1楼网友:旧脸谱
- 2021-04-11 10:29
用FORMAT()
- 2楼网友:掌灯师
- 2021-04-11 10:13
用格式化输出
vbTab帮你搞定
- 3楼网友:西岸风
- 2021-04-11 09:31
用空格是可以对齐的,你把字体设为宋体就可以