Olaf Doschke
Programmer
I encountered problems positioning a form, and I think this is a bug. Can you confirm this? Does anybody know what's going on?
Code to reproduce at the end.
I start a form with a red container, that has the target position and size of a child form. To illustrate what happens I show the subform and made screenshots what happens in each step of setting this forms left, top, width and height. The childform is set to have no border and titlebar and green backcolor, so it looks like just another green container, but the green rectangle is a subform put inside the main form via Windows SetParent and the red rectangle is a container within the main form.
The initial situation is as expected: SetParent works and puts the child into the main form into the top left corner. The target red rectangle is put there to be fully seen right now:
So far, so fine, now the first step is to change the left property of the green form:
The left position is correct, [highlight #FCE94F]but why did the top position change?[/highlight]
Ok, that wouldn't matter, as the next step can mend that, setting top:
Yes, the .Top position now is correct, [highlight #FCE94F]but why did left change once more?[/highlight]
The next two steps are unspectacular, they give the green form the correct size:
And last not least the workaround also is more elegant than setting all these properties one by one:
Using the Form.Move method on the green form puts the form into the right place with the (still) right size. You can also skip all the single steps and just do this, it's not needing already correct size, as Move not only sets Top and Left position but also Width and Height.
What happened here?
Is this Windows 10 (build 1803)?
Is it VFP (I use VFP9 with latest hotfix 09.00.0000.7423)?
Can you reproduce this?
Code to Reproduce:
As the code shows the child form is simply created by createobject("form") and also the main form is just a native base form, nothing special, no anchoring, nothing in that direction.
Thankfully Form.Move() is solving the issue, but if you inspect values of the subform properties you get strange values, too, different from the values just set. The container1 properties are fine all the way, but subform.left and top aren't just visually wrong, their values are even something else than what was set and what is effectively shown!
This is one of the weirdest bugs I've seen.
While Move works, it's a cumbersome workaround, if you only want to change one Property, like Left or Top position only.
Also notice the Top and Left position of the oSubform are also differing from what you see. For example, when the top positions are visually perfectly aligned, I get top=254 from the red container1 and top=481 from the green oSubform! And the form position isn't related to desktop or _screen (0,0), if you move the form around the subform follows as child form; its left and top values don't change and remain wrong. So you can't set these properties right and you can't read these properties right. Even after a Form.Move(), which means Left/Top are broken properties of forms. Why? How?
Bye, Oöaf.
Olaf Doschke Software Engineering
Code to reproduce at the end.
I start a form with a red container, that has the target position and size of a child form. To illustrate what happens I show the subform and made screenshots what happens in each step of setting this forms left, top, width and height. The childform is set to have no border and titlebar and green backcolor, so it looks like just another green container, but the green rectangle is a subform put inside the main form via Windows SetParent and the red rectangle is a container within the main form.
The initial situation is as expected: SetParent works and puts the child into the main form into the top left corner. The target red rectangle is put there to be fully seen right now:
So far, so fine, now the first step is to change the left property of the green form:
The left position is correct, [highlight #FCE94F]but why did the top position change?[/highlight]
Ok, that wouldn't matter, as the next step can mend that, setting top:
Yes, the .Top position now is correct, [highlight #FCE94F]but why did left change once more?[/highlight]
The next two steps are unspectacular, they give the green form the correct size:
And last not least the workaround also is more elegant than setting all these properties one by one:
Using the Form.Move method on the green form puts the form into the right place with the (still) right size. You can also skip all the single steps and just do this, it's not needing already correct size, as Move not only sets Top and Left position but also Width and Height.
What happened here?
Is this Windows 10 (build 1803)?
Is it VFP (I use VFP9 with latest hotfix 09.00.0000.7423)?
Can you reproduce this?
Code to Reproduce:
Code:
oTestform = CreateObject("formbug")
oTestform.Show(1)
**************************************************
*-- Form: form1 (...\vfp\tests\forms\formbug.scx)
*-- ParentClass: form
*-- BaseClass: form
*-- Time Stamp: 07/13/18 11:43:12 PM
*
DEFINE CLASS formbug AS form
Top = 16
Left = 18
Height = 554
Width = 530
DoCreate = .T.
Caption = "Form1"
lactivated = .F.
Name = "Form1"
ADD OBJECT container1 AS container WITH ;
Top = 264, ;
Left = 96, ;
Width = 288, ;
Height = 144, ;
BorderWidth = 0, ;
BackColor = RGB(255,0,0), ;
BorderColor = RGB(0,0,0), ;
Name = "Container1"
PROCEDURE Activate
If NOT This.lActivated
This.lActivated = .T.
DECLARE SetParent IN WIN32API integer hWndChild, integer hWndParent
Local loSubform
loSubform = CreateObject("form")
loSubForm.BorderStyle = 0
loSubForm.TitleBar = 0
loSubForm.BackColor = Rgb(0,255,0)
SetParent(loSubForm.Hwnd, This.HWnd)
* To illustrate what happens show the form BEFORE adjusting position and size
loSubForm.Show()
This.AddProperty("oSubform",loSubform)
Endif
ENDPROC
PROCEDURE Click
Set Step On
* doesn't work
This.oSubform.Left = This.container1.Left
This.oSubform.Top = This.container1.Top
This.oSubform.Width = This.container1.Width
This.oSubform.Height = This.container1.Height
* works
This.oSubform.Move( ;
This.container1.left ,;
This.container1.top ,;
This.container1.width,;
This.container1.height)
ENDPROC
ENDDEFINE
*
*-- EndDefine: formbug
**************************************************
As the code shows the child form is simply created by createobject("form") and also the main form is just a native base form, nothing special, no anchoring, nothing in that direction.
Thankfully Form.Move() is solving the issue, but if you inspect values of the subform properties you get strange values, too, different from the values just set. The container1 properties are fine all the way, but subform.left and top aren't just visually wrong, their values are even something else than what was set and what is effectively shown!
This is one of the weirdest bugs I've seen.
While Move works, it's a cumbersome workaround, if you only want to change one Property, like Left or Top position only.
Also notice the Top and Left position of the oSubform are also differing from what you see. For example, when the top positions are visually perfectly aligned, I get top=254 from the red container1 and top=481 from the green oSubform! And the form position isn't related to desktop or _screen (0,0), if you move the form around the subform follows as child form; its left and top values don't change and remain wrong. So you can't set these properties right and you can't read these properties right. Even after a Form.Move(), which means Left/Top are broken properties of forms. Why? How?
Bye, Oöaf.
Olaf Doschke Software Engineering