vb6.0的combobox里面的文字如何居中显示,求救

解决方案 »

  1.   

    我记得combobox本身应该是办不到的啊,就处划.net里的好像也一样,看来你要找下自画的资料,ownerdraw.
      

  2.   

    问题是文字的宽度怎么计算呢,用len只能求出多少个字符,也无法计算他的像素宽啊
      

  3.   

    问题是文字的宽度怎么计算呢,用len只能求出多少个字符,也无法计算他的像素宽啊是可以计算的:
    效果图如下:Option ExplicitPrivate Sub Form_Load()
        Dim i As Long, W1 As Long, W2 As Long, W3 As Long, S As String, arr() As String
            
        Me.ScaleMode = 3
        
        Combo1.AddItem "C"
        Combo1.AddItem "CS"
        Combo1.AddItem "CSD"
        Combo1.AddItem "CSDN中文网站"
            
        Me.Font.Size = 48
        Me.FontName = "黑体"
        Combo1.Font.Size = Me.Font.Size
        Combo1.FontName = Me.FontName
        W2 = Me.TextWidth(" ")
        W3 = Combo1.Width '/ Screen.TwipsPerPixelX
        ReDim arr(Combo1.ListCount - 1)
        For i = 0 To Combo1.ListCount - 1
            S = Combo1.List(i)
            S = Trim(S)
            W1 = Me.TextWidth(S)
            arr(i) = Space(((W3 - W1) / 2) / W2) & S
        Next
        
        Combo1.Clear
        
        For i = 0 To UBound(arr)
            Combo1.AddItem arr(i)
        Next
        Combo1.ListIndex = Combo1.ListCount - 1
        
    End Sub
      

  4.   

    如果你说的是ComboBox的文本框中的文字,可以设置对齐方式,因为它就是一个标准的文本框。至于下拉,标准的做法是Owner Redraw。
      

  5.   

    问题是文字的宽度怎么计算呢,用len只能求出多少个字符,也无法计算他的像素宽啊是可以计算的:
    效果图如下:Option ExplicitPrivate Sub Form_Load()
        Dim i As Long, W1 As Long, W2 As Long, W3 As Long, S As String, arr() As String
            
        Me.ScaleMode = 3
        
        Combo1.AddItem "C"
        Combo1.AddItem "CS"
        Combo1.AddItem "CSD"
        Combo1.AddItem "CSDN中文网站"
            
        Me.Font.Size = 48
        Me.FontName = "黑体"
        Combo1.Font.Size = Me.Font.Size
        Combo1.FontName = Me.FontName
        W2 = Me.TextWidth(" ")
        W3 = Combo1.Width '/ Screen.TwipsPerPixelX
        ReDim arr(Combo1.ListCount - 1)
        For i = 0 To Combo1.ListCount - 1
            S = Combo1.List(i)
            S = Trim(S)
            W1 = Me.TextWidth(S)
            arr(i) = Space(((W3 - W1) / 2) / W2) & S
        Next
        
        Combo1.Clear
        
        For i = 0 To UBound(arr)
            Combo1.AddItem arr(i)
        Next
        Combo1.ListIndex = Combo1.ListCount - 1
        
    End Sub为什么我这个会出错呢?