ImageMan ActiveX
Placing Other Controls on the ImageMan Control

When using ImageMan as a control container it is often hard to place the control correctly on the ImageMan control. There are further difficulties when the image is moved or resized. This is because ImageMan uses it's own scaling method that is always relative to the image and not the form. To get this code to work place a shape and a label control inside the ImageMan control.


Dim ScaleRatio As Double

' Note this code will work when the control is displayed

' At any size and position it just needs to be "Refreshed"

' Each time size or position change

If ImageControl1.GetFilename <> True Then Exit Sub


ImageControl1.AutoScale = MaintainAspect


ScaleRatio = ImageControl1.Height / ImageControl1.ScaleHeight


' The following code places shape1 around the left upper

' One quarter of the image (Quadrant II)

Shape1.Left = 0

Shape1.Top = 0

Shape1.Height = (ImageControl1.ImageHeight / 2) * ScaleRatio

Shape1.Width = (ImageControl1.ImageWidth / 2) * ScaleRatio



' This code places Label1 at specified spot

Label1.ForeColor = &HFFFF&

Label1.BackStyle = 0 ' Transparent

Label1.Left = 100 * ScaleRatio

Label1.Top = 100 * ScaleRatio

Label1.Width = 150 * ScaleRatio

Label1.Height = 30 * ScaleRatio



The control placement on a form in Visual Basic is always relative to the scaling method used by the form. Even when the controls are placed on top of another control. Setting the Form scaling method to Pixels would only work when the image is full size. By using the ScaleRatio in the above code you can allow for accurate placement of controls even when the image is not being displayed full size.



© 2014 Data Techniques, Inc. All rights reserved.

Submit feedback on this topic