Hi

I want to move a button control between two panels each time it is clicked.
For example

The code in the click event of the button would follow the following pseudocode:

if button is on panel1 Then
set container of button to panel2
Else if button is on panel2 Then
set container of button to panel1
End If

In VB6 I would do the following:
VB Code:
  1. If cmdButton1.Container.name = frame1 Then
  2.   set cmdButton1.Container = frame2
  3. Else if cmdButton1.Container.name = frame2 Then
  4.   set cmdButton1.Container = frame1
  5. End If

In VB.NET I'm currently doing the following:

[Highlight=VB]

If CType(sender, Button).Tag = "panel1" Then
panel1.Controls.Remove(sender)
panel2.Controls.Add(sender)
Else
panel2.Controls.Remove(sender)
panel1.controls.Add(sender)
End If

[Highlight=VB]

Am i doing the right thing or is there an alternative to this?

Thanks