首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

vb combobox的高度是只读属性,要怎样才能改变它的高度,多谢大侠们

2012-06-05 
vb combobox的高度是只读属性,要怎样才能改变它的高度,谢谢大侠们!如题:我想要的效果是在窗体大小变化时,c

vb combobox的高度是只读属性,要怎样才能改变它的高度,谢谢大侠们!
如题:
  我想要的效果是在窗体大小变化时,combobox的大小也能随之而改变,但是combobox控件的高度是只读的,不能改变,所以不能随窗体大小而改变,请问这个问题要怎样解决,谢谢。

[解决办法]
加QQ:909413335
我这里有个控件,实现窗体控件缩放的

写这么长的代码不累啊?
[解决办法]

VB code
Private Declare Function SendMessage Lib _  "USER32" Alias "SendMessageA" _  (ByVal hwnd As Long, ByVal Msg As Long, _  ByVal wParam As Long, ByVal lParam As Long) As Long      Private Const CB_ERR       As Long = -1  Private Const CB_SETITEMHEIGHT       As Long = &H153      Private Sub Command1_Click()  '稍小一点的高度              SendMessage Me.Combo1.hwnd, CB_SETITEMHEIGHT, -1, 50          Combo1.Refresh              End Sub      Private Sub Command2_Click()  '稍大一点的高度          SendMessage Me.Combo1.hwnd, CB_SETITEMHEIGHT, -1, 100          Combo1.Refresh                  End Sub
[解决办法]
VB code
Option ExplicitPrivate FormOldWidth    As Long    '保存窗体的原始宽度Private FormOldHeight    As Long    '保存窗体的原始高度  '在调用ResizeForm前先调用本函数  Public Sub ResizeInit(FormName As Form)      Dim Obj    As Control      FormOldWidth = FormName.ScaleWidth      FormOldHeight = FormName.ScaleHeight      On Error Resume Next      For Each Obj In FormName          If TypeOf Obj Is ComboBox Then                Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.FontSize & " "          ElseIf TypeOf Obj Is Line Then                Obj.Tag = Obj.X1 & " " & Obj.X2 & " " & Obj.Y1 & " " & Obj.Y2 & " " & Obj.BorderWidth & " "          Else                Obj.Tag = Obj.Left & " " & Obj.Top & " " & Obj.Width & " " & Obj.Height & " "          End If      Next Obj      On Error GoTo 0  End Sub  '按比例改变表单内各元件的大小,在调用ReSizeForm前先调用ReSizeInit函数  Public Sub ResizeForm(FormName As Form)      Dim Pos(4)    As Double      Dim i    As Long, TempPos      As Long, StartPos      As Long      Dim Obj    As Control      Dim ScaleX    As Double, ScaleY      As Double      ScaleX = FormName.ScaleWidth / FormOldWidth          '保存窗体宽度缩放比例      ScaleY = FormName.ScaleHeight / FormOldHeight          '保存窗体高度缩放比例      On Error Resume Next      For Each Obj In FormName          StartPos = 1          For i = 0 To 5          '读取控件的原始位置与大小              TempPos = InStr(StartPos, Obj.Tag, " ", vbTextCompare)              If TempPos > 0 Then                  Pos(i) = Mid(Obj.Tag, StartPos, TempPos - StartPos)                  StartPos = TempPos + 1              Else                  Pos(i) = 0              End If        '根据控件的原始位置及窗体改变大小的比例对控件重新定位与改变大小          Next i                      If TypeOf Obj Is ComboBox Then                Obj.FontSize = Pos(3) * ScaleY                Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX            ElseIf TypeOf Obj Is Line Then                Obj.X1 = Pos(0) * ScaleX                Obj.X2 = (Pos(1) - Pos(0)) * ScaleX + Obj.X1                Obj.Y1 = Pos(2) * ScaleY                Obj.Y2 = (Pos(3) - Pos(2)) * ScaleY + Obj.Y1                Obj.BorderWidth = Pos(4) * Sqr(ScaleX * ScaleX + ScaleY * ScaleY)            Else                Obj.Move Pos(0) * ScaleX, Pos(1) * ScaleY, Pos(2) * ScaleX, Pos(3) * ScaleY            End If      Next Obj      On Error GoTo 0  End SubPrivate Sub Form_Initialize()    Call ResizeInit(Me)End SubPrivate Sub Form_Resize()    Call ResizeForm(Me)End Sub 

热点排行