1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

move a panel from one form to another

Discussion in 'Questions (Windows Mobile)' started by pochero, Feb 6, 2009.

  1. pochero

    pochero Member Licensed User

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

    digitaldon37 Active Member Licensed User

    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
     
  3. pochero

    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.
     
  4. klaus

    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.

     

    Attached Files:

  5. pochero

    pochero Member Licensed User

    Thank you very much, it works.
     
  6. pochero

    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
     
  7. klaus

    klaus Expert Licensed User

    It works !

    Try the example below.

    I added Panel1.BringToFoint here:
    Code:
    [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.
     
  8. pochero

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice