Change Parent?

jgm

Member
Licensed User
I tried to find out how to cut and paste controls like Labels and TextBoxes between forms?
I do not know if that is possible or makes sense?
I am not sure if change parent Tool is used for that and how it works.

JM
 

jgm

Member
Licensed User
Hi,

I meant switching controls still in design phase.
Suppose you have form1 populated with controls, and form 2, and you want to move some controls from form1 to form2.
I was wondering if instead of deleting those controls in form2 and creating them again in form1, some sort of "cut" and "paste" wouldn't work and how to do it?

JGM
 

jgm

Member
Licensed User
It would be nice to be able to do cut and paste of controls between forms.
In my case I developed a small program for my PDA which has seven screens full of Labels and TextBoxes for data input, calculations and output.
Now I want to use that application on my desktop, and since desktop supports a larger screen it would be nice to join all those data fields in one larger screen; and doing that with cut and paste would be much more easier and faster than deleting and creating those controls again.
Perhaps you could consider that possibility in future releases.
Thanks for your help.
 

klaus

Expert
Licensed User
Longtime User
There is a possibility with a text editor.
You can modify the form name in the editor an save the file.
In the attached exapmle I move Labe2 and TextBox2 from Form1 to Form2.
Be carefull, make the changes on a copy of the original file. If you make mistakes, the file could be corrupred and no more be redable by the B4PPC editor.
I had copied Panels with a lot of controls from one program to another one this way with Notepad.

Original file:
B4X:
version
6.50
1
Form1
Form2
238
268
0
0
0
0
Sub designer
addform(Form1,"Form1","",220,220,220)@
[COLOR=red]addtextbox(form1,TextBox2,25,140,75,22,"TextBox2",255,255,255,0,0,0,True,True,False,9)@[/COLOR]
addtextbox(form1,TextBox1,25,105,75,22,"TextBox1",255,255,255,0,0,0,True,True,False,9)@
[COLOR=red]addlabel(form1,Label2,25,75,75,25,"Label2",220,220,220,0,0,0,True,True,9)@[/COLOR]
addlabel(form1,Label1,25,45,75,25,"Label1",220,220,220,0,0,0,True,True,9)@
addbutton(form1,Button1,140,30,75,23,"Button1",212,208,200,0,0,0,True,True,9)@
addform(Form2,"Form2","",220,220,220)@
addbutton(form2,Button2,115,55,75,23,"Button2",212,208,200,0,0,0,True,True,9)@
End Sub
@EndOfDesignText@
Sub Globals
 'Declare the global variables here.
End Sub
Sub App_Start
 Form1.Show
End Sub

new file:
B4X:
version
6.50
1
Form1
Form2
238
268
0
0
0
0
Sub designer
addform(Form1,"Form1","",220,220,220)@
addtextbox(form1,TextBox1,25,105,75,22,"TextBox1",255,255,255,0,0,0,True,True,False,9)@
addlabel(form1,Label1,25,45,75,25,"Label1",220,220,220,0,0,0,True,True,9)@
addbutton(form1,Button1,140,30,75,23,"Button1",212,208,200,0,0,0,True,True,9)@
addform(Form2,"Form2","",220,220,220)@
addbutton(form2,Button2,115,55,75,23,"Button2",212,208,200,0,0,0,True,True,9)@
[COLOR=darkgreen]addlabel([COLOR=red]form2[/COLOR],Label2,25,75,75,25,"Label2",220,220,220,0,0,0,True,True,9)@[/COLOR]
[COLOR=darkgreen]addtextbox([COLOR=red]form2[/COLOR],TextBox2,25,140,75,22,"TextBox2",255,255,255,0,0,0,True,True,False,9)@[/COLOR]
End Sub
@EndOfDesignText@
Sub Globals
 'Declare the global variables here.
End Sub
Sub App_Start
 Form1.Show
End Sub

I moved the red lines at the green position after the declaration of Form1. And changed form1 into form2.
Note that it's form2 and not Form2, you should use lower case characters for the first control names.

Attached the two files.

Best regards.
 
Last edited:

jgm

Member
Licensed User
Hi,

Thanks for your suggestion. It worked fine.
I did not know one could open and edit source files with a text editor.

If you want to move few controls, that would work with no problem.
But if you have several forms to merge into one form, that would be much more complicated;
If you just change those controls records (renaming the parent field from say form4 to form1) and position those records after the addform record for form1 you probably would get a lot of controls overlapping each other.
That gave me an idea of an utility that could be built (with B4PPC of course) that would solve most of the problem.

Suppose you have an application with six screens for PPC and you want to merge those six screens into one on your desktop.
You could edit the source file with B4PPC and change the screen size doubling the width and tripling the height.
You could imagine this new screen as an array of 3x2 screens (3 rows and two columns of PPC screens set aside).

At first the utility could simply read the source file, identify all forms in the file, and then let you assign each form a destination area in the new form (one of the six positions of the array).

Then the utility would have to do the following:
1. Change the parents control name for each record control being moved (say form4 or other to form1).
2. Change the coordinates of the control depending on the area it is being moved to (suppose control X is being moved to the third row column two; you would have to had to the Top and Left coordinates of X control the coordinates of the Top Left position of the destination screen area).
3. Write out the source file positioning the changed records after the addform record for form1.

You would get a source file with all controls in form1 and none overlapping.

I believe this utility would be very simple to build to an expert (that I am not).
I'll give it a try in my spare time.

Thanks for your help.

Best regards
 
Top