-
Notifications
You must be signed in to change notification settings - Fork 3
Manage added objects
Visual controls can be added to a form at runtime and immediately placed and dimensioned considering the current DPI scale.
The manager must be notified that the control is added. Usually, this will be done when the control becomes visible, as it happens with forms. The dimensional and positional properties of the control must be set as if they would be inserted into a 100% monitor.
Suppose the position and size of the new control are absolute. In that case, it's just a matter of setting them before DPI-aware management is triggered, together with other properties required to prepare the control rendering.
* create a new label in a form, absolute position and size
Thisform.AddObject("myLabel", "label")
Thisform.myLabel.Top = 100
Thisform.myLabel.Left = 4
Thisform.myLabel.FontSize = 9
Thisform.myLabel.AutoSize = .T.
Thisform.myLabel.Caption = "A new label"
Thisform.DPIAwareManager.AddControl(Thisform.myLabel)
Thisform.myLabel.Visible = .T.If the control depends on other objects in the form, use the DPIAware_ copies to set the new object properties relative to the original properties of the objects on which it depends.
* create a new label in a form, relative position and size
Thisform.AddObject("myLabel", "label")
Thisform.myLabel.Top = Thisform.lblTitle.DPIAware_Top + Thisform.lblTitle.DPIAware_Height + 4 && just a margin...
Thisform.myLabel.Left = Thisform.lblTitle.DPIAware_Left
Thisform.myLabel.FontSize = Thisform.lblTitle.DPIAware_FontSize - 2
Thisform.myLabel.AutoSize = .T.
Thisform.myLabel.Caption = "A new label"
Thisform.DPIAwareManager.AddControl(Thisform.myLabel)
Thisform.myLabel.Visible = .T.