move a panel from one form to another

pochero

Member
Licensed User
Is it possible to move a panel (with its components), from one form to another? Thank you.
 

digitaldon37

Active Member
Licensed User
Is it possible to move a panel (with its components), from one form to another? Thank you.
You might try the ChangeParent command

Changes a control parent.
Using ChangeParent you can move a control from one form to another.
Syntax: ChangeParent (Control As Control, Parent As Control)
Control - The name of the control that will be moved.
Parent - The new parent for the control.

Example:
Sub App_Start
Form1.Show
flb.New1("form1",b4pobject(1))
flb.ChangeParent("Button2","Form2") 'Moves Button2 to Form2.
End Sub
 

pochero

Member
Licensed User
Thank you, but it doesn't work for me with a panel, i get an error:

flbPanel.New1("calPanel",B4PObject(1))

Error description:
El objeto de tipo 'Dbasic.EnhancedControls.CEnhancedPanel' no puede convertirse en el tipo 'System.Windows.Forms.Form'.

It can't convert a panel object to a form object.
 

klaus

Expert
Licensed User
You must:
- load the FormLib library
- Add a FormLib object for example flb
- declare the the flb FormLib object with
flb.New1("Form1",B4PObject(1))
- Add somewhere in your, depending on how and when you want to move the panel with.
flb.ChangeParent("Panel1","Form2")

Attached a very small example, it shows you that you can move a panel from Form1 to Form2 and also backwards.

Best regards.

 

Attachments

pochero

Member
Licensed User
I have a problem, when the panel is moved, it is at background of all controls of the destiny form. I try panel.bringToFront but has no effect.
I want the moved panel is in foreground

In your example try to add a buttonX in the form2, when you move the panel, the buttonX appears on top of the panel's button.

Thank you
 

klaus

Expert
Licensed User
It works !

Try the example below.

I added Panel1.BringToFoint here:
B4X:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]Sub [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]btnMovePanel_Click[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]flb.ChangeParent([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Panel1"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Form2"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
[SIZE=2][FONT=Courier New]Panel1.BringToFront[/FONT][/SIZE]
[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
I added Button1 on Form2 and the panel hides it. You can move the panel down and up to see and hide this button.

Notice that Button2 belongs to Panel1, this just to show that the panel is moved with it's controls.

Best regards.
 

pochero

Member
Licensed User
Thank you very much, I create the objects dynamically, and i did the "bringToFront" before creating the statics objects. Thanks again.
 
Top