标签也只能显示一种字体与颜色,下面是把标签1和标签2无缝组合到一起
Command1_Click事件基本没有问题,有点小小的改动:
程序代码:
Private Sub Form_Load() Text1.Text = "西瓜1 菠萝5 蜜桃3 番茄4 苹果0 柚8" Label1.Caption = "" Label2.Caption = "" '========================== Label1.Width = 2415 Label1.Height = 800 Label1.FontBold = False '标签1不是粗体 Label1.ForeColor = &H0 '标签1为黑色 Label2.Width = Label1.Width Label2.Height = Label1.Height Label2.Left = Label1.Left + Label1.Width '标签2的位置紧接着标签1 Label2.Top = Label1.Top Label2.FontBold = True '标签2为粗体 Label2.ForeColor = &H1000FF '标签2为红色 '======以上是把标签1和标签2无缝组合到一起============ End Sub
Command1_Click事件基本没有问题,有点小小的改动:
程序代码:
Private Sub Command1_Click() Dim B, I As Integer, J As Integer, C() As String, D() As String Label1.Caption = "" Label2.Caption = "" B = Array("菠萝", "桔子", "西瓜", "番茄", "苹果", "柚子") 'Text1.Text = Replace(Text1.Text, " ", ",") 不需要将空格转换为逗号 D() = Split(Text1.Text, " ") '判断空格就可以 For I = 0 To UBound(D) D(I) = Trim(D(I)) '这里将字符串的前后空格去除 Next I ReDim C(0 To UBound(D)) 'C的下标应该与D的下标相同 For I = 0 To UBound(D) For J = 0 To UBound(B) If InStr(1, D(I), B(J), 1) > 0 Then C(I) = "存在" End If Next J Next I For I = 0 To UBound(D) If C(I) = "存在" Then Label1.Caption = Label1.Caption & D(I) & Space(3) ElseIf C(I) = "" Then Label2.Caption = Label2.Caption & D(I) & Space(3) End If Next I End Sub
[此贴子已经被作者于2017-10-16 10:03编辑过]
请不要选我!!!