Excel VBA:框架未出现在列表框前面

问题描述 投票:0回答:1

我有一个包含其他控件的框架,还有一个列表框。所有这些都在用户表单内。最初,框架是不可见的,并且有一个按钮可以切换其可见性。我希望框架及其内容出现在列表框前面,但是,这不会发生。

我尝试使用“格式”菜单的“顺序”部分将框架置于前面并将列表框发送到后面,但这并没有改变任何东西。我补充了。

'Bring it to the front
DatePickerFrame.ZOrder (0)
    
'Send the ListBox to the back
SearchResultsListBox.ZOrder (1)

我的用户表单的初始化,这导致在切换日历框架的可见性时出现这种情况:

但在关闭日历框架的可见性时也会导致此问题:

我还将此代码剪切并粘贴到切换日历可见性的按钮中,但它导致了相同的行为。

excel vba controls userform z-order
1个回答
0
投票

出于某种原因(我还没弄清楚为什么),当你将某些东西变为可见而它与其他东西重叠时,重叠仍然存在..

开始:

点击按钮时:

再次点击时(仍然重叠):

我曾经使用过的代码最终在将框架恢复为不可见时仅显示列表框:

Private Sub CommandButton2_Click()
    Frame1.Visible = Not Frame1.Visible
    ListBox1.Visible = False 'this is absolutely necessary
    ListBox1.Visible = True
    Frame1.ZOrder (IIf(Frame1.Visible, 0, 1)) 'needs to come after making the listbox (in)visible.
    'ListBox1.ZOrder (IIf(Frame1.Visible, 1, 0)) 'not necessary since you want the frame to be in front
End Sub

如果这不是问题,请告诉我,我会检查更多:)

© www.soinside.com 2019 - 2024. All rights reserved.