0

我正在研究 VB.NET

我有一个用(除其他外)面板和一些按钮创建的表单。

按钮的默认可见属性值为 true。但是,当我启动表单时,它们是不可见的。

我调查发现,在设计器生成的代码中,按钮在添加到面板时是可见的,而在将面板添加到主窗体时,它们变得不可见。

这是我的代码的预览:

'ActionsPanel is the panel which contains the buttons
Me.ActionsPanel.Controls.Add(Me.SaveButton)
Me.ActionsPanel.Controls.Add(Me.DeleteButton)
Me.ActionsPanel.Controls.Add(Me.NewButton)
Me.ActionsPanel.Controls.Add(Me.OpenButton)
'So far the buttons are visible

Me.Controls.Add(Me.ActionsPanel)
'Me refers to the parent form of the controls
'As of here the buttons become invisible

因此,在将面板添加到表单的行中,按钮变得不可见。

我试图使用调试器强制它们为真,只是为了测试,但属性没有改变(参见视频投射:视频

有人有想法吗?

谢谢。

4

3 回答 3

2

我今天遇到了类似的问题(尽管我再也看不到视频了),在我的具体情况下,问题是我设置了一个控件的可见属性,该控件是另一个控件的子控件。

如果我做了child.visible=true然后if child.visible,结果是false

我发现如果我再设置parent.visible=truethenchild.visible也会变成true. 实际上,看起来子控件仅在父控件可见时才报告其定义的状态。

希望这可以帮助一些人,即使这个线程已经超过 2 年了。

于 2016-02-02T22:55:34.973 回答
0
'ActionsPanel is the panel which contains the buttons
Me.ActionsPanel.Controls.Add(Me.SaveButton)
Me.ActionsPanel.Controls.Add(Me.DeleteButton)
Me.ActionsPanel.Controls.Add(Me.NewButton)
Me.ActionsPanel.Controls.Add(Me.OpenButton)

这显示您将按钮从表单添加到面板。由于您不更改位置,因此它们不在可见区域内的可能性很高。并不是 visible 属性为 False,而是它们不可见或不可见。它不断变回,因为它们不在可视区域内。

dim btn as Button = Me.SaveButton
Me.ActionsPanel.Controls.Add(btn)
btn.Location = new point (10,10)      ' maybe other properties too

btn = Me.DeleteButton
Me.ActionsPanel.Controls.Add(btn)
btn.Location = new point (10,40)
于 2013-11-02T20:06:52.793 回答
0

利用

Me.ActionsPanel.Controls.Add(Button1)

代替

Me.ActionsPanel.Controls.Add(Me.Button1)

希望这可以帮助。

另外,如果您想移动它,请使用

Button1.Location = New Point(X, Y)
于 2013-11-02T20:53:12.113 回答