我想在其他两个控件之间动态插入一个面板(用户控件)。假设我有一个 PictureBox(Control) 作为父级,图片框上还有一个其他控件。
我想从图片框中删除另一个控件,向图片框中添加一个面板(控件),然后将旧控件设置为新面板。现在我有这个代码:
If m_targetDisplay.MainDoubleBufferedPictureBox.HasChildren Then
For Each child As Control In m_targetDisplay.MainDoubleBufferedPictureBox.Controls
If (child.BackColor = Drawing.Color.Transparent) Then
Dim panel As SXFadeWrapperForGPU = New SXFadeWrapperForGPU()
panel.ClientSize = New Size(child.ClientSize.Width, child.ClientSize.Height)
panel.Location = New System.Drawing.Point(child.Location.X, child.Location.Y)
m_targetDisplay.MainDoubleBufferedPictureBox.Controls.Add(panel)
panel.Controls.Add(child)
m_targetDisplay.MainDoubleBufferedPictureBox.Controls.Remove(child)
AddHandler panel.Paint, AddressOf PanelPaintEvent
End If
Next
End If
我的代码正在向它前面的透明颜色子项添加一个背景包装器。问题是即使我在添加之前或添加回来之后删除了孩子,我也永远无法在屏幕上看到它。有没有什么特别的事情可能是 Remove 做的,所以被删除的 Child 不再可用?
您应该将子位置更改为 (0, 0),否则它仍将相对于其在 MainDoubleBufferedPictureBox 中的位置,但现在它位于新面板中。它可能就在那里,就在面板边界之外
If m_targetDisplay.MainDoubleBufferedPictureBox.HasChildren Then
For Each child As Control In m_targetDisplay.MainDoubleBufferedPictureBox.Controls
If (child.BackColor = Drawing.Color.Transparent) Then
Dim panel As SXFadeWrapperForGPU = New SXFadeWrapperForGPU()
panel.ClientSize = New Size(child.ClientSize.Width, child.ClientSize.Height)
panel.Location = New System.Drawing.Point(child.Location.X, child.Location.Y)
m_targetDisplay.MainDoubleBufferedPictureBox.Controls.Add(panel)
panel.Controls.Add(child)
child.Location = New System.Drawing.Point(0, 0) ' <--- this
m_targetDisplay.MainDoubleBufferedPictureBox.Controls.Remove(child)
AddHandler panel.Paint, AddressOf PanelPaintEvent
End If
Next
End If
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句