Option Explicit
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Form_Load()
SetParent Text1.hWnd, Toolbar1.hWnd
Text1.Move 0, 0
Text1.Visible = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
SetParent Text1.hWnd, Me.hWnd
End Sub
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Form_Load()
SetParent Text1.hWnd, Toolbar1.hWnd
Text1.Move 0, 0
Text1.Visible = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
SetParent Text1.hWnd, Me.hWnd
End Sub
这只是部分的代码,其实在vb的在线帮助里就有介绍的Dim btnX As Button'向 Toolbar 控件添加一个 Textbox 控件
Set btnX = Toolbar1.Buttons.Add(, "textbox1", , tbrPlaceholder)
btnX.Width = 1500
With Text1
.Left = Toolbar1.Buttons("textbox1").Left
.Top = Toolbar1.Buttons("textbox1").Top + 30
.Width = Toolbar1.Buttons("textbox1").Width
'.Height = Toolbar1.Buttons("textbox1").Height
End With
你这样叫添加一个文本框吗?
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Dim WithEvents Text1 As VB.TextBox
Private Sub Form_Load()
Set Text1 = Controls.Add("vb.textbox", "Text1")SetParent Text1.hWnd, Toolbar1.hWnd
Text1.Move 0, 0
Text1.Visible = True
End SubPrivate Sub Form_Unload(Cancel As Integer)
SetParent Text1.hWnd, Me.hWnd
End Sub
我在MDIFORM中用,运行说textbox无对齐属性,不能用在MDIFORM中,怎么办?
然后直接把textbox画到toolbar上面
toolbar本身就是容器,它有对齐属性,如果需要动态创建textbox
huangguanshu说的对