Vb.net 在Windows窗体中的两个控件之间插入面板
我想在另外两个控件之间动态插入一个面板(用户控件)。假设我有一个PictureBox(控件),因为父控件在PictureBox上有另一个控件 我想从图片框中删除另一个控件,向图片框添加一个面板(控件),然后将旧控件设置为新面板。目前,我有以下代码:Vb.net 在Windows窗体中的两个控件之间插入面板,vb.net,winforms,Vb.net,Winforms,我想在另外两个控件之间动态插入一个面板(用户控件)。假设我有一个PictureBox(控件),因为父控件在PictureBox上有另一个控件 我想从图片框中删除另一个控件,向图片框添加一个面板(控件),然后将旧控件设置为新面板。目前,我有以下代码: If m_targetDisplay.MainDoubleBufferedPictureBox.HasChildren Then For Each child As Control In m_targetDisplay.MainDou
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
我的代码正在为它前面的透明颜色子对象添加一个背景包装器。问题是,即使我在添加之前或添加之后删除了子对象,我也永远无法在屏幕上看到它。有没有什么特别的事情可能是删除会导致被删除的子对象不再可用?您应该将子对象位置更改为(0,0),否则它仍将相对于其在Main DoubleBufferedPictureBox中的位置,但现在它位于新面板中。它可能就在那里,就在面板边界之外
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
如果m_targetDisplay.main DoubleBufferedPictureBox.HasChildren
对于m_targetDisplay.main DoubleBufferedPictureBox.Controls中的每个子控件
如果(child.BackColor=Drawing.Color.Transparent),则
尺寸面板为SXFadeWrapperForGPU=新SXFadeWrapperForGPU()
panel.ClientSize=新大小(child.ClientSize.Width、child.ClientSize.Height)
panel.Location=New System.Drawing.Point(child.Location.X,child.Location.Y)
m_targetDisplay.main DoubleBufferedPictureBox.Controls.Add(面板)
panel.Controls.Add(子项)
child.Location=New System.Drawing.Point(0,0)'这不是c#据我所知是vb。.这代码不是c#?似乎是VB?哦,完全是我的错,我会编辑,你应该将子对象
位置更改为(0,0),否则它仍然会相对于它在main doublebufferedpicturebox
中的位置,但现在它在新面板中。它可能在那里,就在面板边界之外。事实上,你是对的,在调试时,我意识到代码中还有其他地方重置了子位置,所以我只是改变了它,现在它工作了!谢谢我自己会花很长时间来解决这个问题!这就是我们在这里的原因:)