我做了一个自定义组合控件MyCox,类似于ComboBox,我的做法是,点击一个按纽把另一个控件(TreeView)显示出来
可是遇到一个问题,就是TreeView不能显示出来,原因是它的显示范围不能超过MyCox,另一方法我又不能把MyCox设计的过大,因为会遮住其它控件的。后来我又想到把TreeView父窗口变成主窗口,但这样又出现了一个问题,移出来后,变成了两个控件了即MyOcx和TreeView,这样焦点就不好控制了
请求达了指点一下,谢谢。
6 个解决方案
你可以把两个控件放在一个panel上,控制panel的高度来显示或隐藏treeview
写了一个,看看不知道合不合适
Private Sub ResizeConstrols()
If tview.Visible = False Then
Me.Height = txtInput.Height
btnDown.Top = txtInput.Top + 2
btnDown.Left = txtInput.Width - btnDown.Width - 3
txtInput.Width = Me.Width
tview.Width = Me.Width
Else
Me.Height = txtInput.Height + tview.Height
btnDown.Top = txtInput.Top + 2
btnDown.Left = txtInput.Width - btnDown.Width - 3
txtInput.Width = Me.Width
tview.Width = Me.Width
End If
End Sub
Private Sub UserCtrl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txtInput.Left = 0
txtInput.Top = 0
tview.Left = 0
tview.Top = txtInput.Height + 2
ResizeConstrols()
btnDown.Tag = False
End Sub
Private Sub txtInput_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtInput.SizeChanged
ResizeConstrols()
End Sub
Private Sub tview_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tview.SizeChanged
ResizeConstrols()
End Sub
Private Sub UserCtrl_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
ResizeConstrols()
End Sub
Private Sub btnDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDown.Click
If btnDown.Tag = False Then
tview.Visible = True
btnDown.Tag = True
ResizeConstrols()
Else
tview.Visible = False
btnDown.Tag = False
ResizeConstrols()
End If
End Sub
to aimcy()
你把整个控年的size拉大,会遮住别的控件的
因为如果把树的控件的宽度超过文本框的宽度,如果把整个控件的宽度变成跟树一下的宽度的话,这样右上角一块会遮住下面的东西的。