Dynamically Positioning the Control (Visual Basic Script)

Take the following steps to dynamically scale and position the LEAD RasterView control when loading an image. This example scales the control to use most of the browser’s area while preserving the image's aspect ratio.

1.

Start with the project that you created in Loading and Displaying an Image.

2.

Delete the <FORM> </FORM> tags and what’s between them and the LoadImage subroutine, and replace the code in the Window_OnLoad subroutine with the following code:

Dim HeightFactor 
Dim WidthFactor 
Dim HeightAllowed 
Dim WidthAllowed 
Dim NewWidth 
Dim NewHeight 

'Modify the browser window’s size and position so that it takes up most of the screen. 
NewHeight = Screen.height * 0.8 
NewWidth = Screen.width * 0.9 
Window.resizeTo NewWidth, NewHeight 
Window.moveTo (Screen.Width - NewWidth) / 2, (Screen.Height - NewHeight) / 2 
LEADRasterView1.ScaleMode = 3 

'Turn off automated behavior while we load and manipulate the image. 
LEADRasterView1.AutoRepaint = False 
LEADRasterView1.AutoScroll = False 
LEADRasterView1.BackErase = False 

'Load the bitmap. This hard-coded path name may be different on your system. 
RasterIO1.Load LeadRasterView1.Raster, "i:\a\pic\20010327047.jpg", 0, 0, 1 

'Set the variables used for preserving the aspect ratio. 
'The units of measure do not matter, since we are calculating proportions. 
HeightFactor = LEADRasterView1.Raster.BitmapHeight 
WidthFactor = LEADRasterView1.Raster.BitmapWidth 
HeightAllowed = NewHeight * 3 / 4 
WidthAllowed = NewWidth * 3 / 4 

'Check to see if using the maximum width will make the image too tall. Set the dimensions based on the result. 
If ((WidthAllowed * HeightFactor) / WidthFactor) < HeightAllowed Then 
LEADRasterView1.Width = WidthAllowed 
LEADRasterView1.Height = (LEADRasterView1.Width * HeightFactor) / WidthFactor 
Else 
LEADRasterView1.Height = HeightAllowed 
LEADRasterView1.Width = (LEADRasterView1.Height * WidthFactor) / HeightFactor 
End If 

'Set the image display size to match the LEAD control 
Dim PAINTSIZEMODE_FIT
PAINTSIZEMODE_FIT = 3
LEADRasterView1.PaintSizeMode = PAINTSIZEMODE_FIT

'Turn on automated behavior while we load and manipulate the image. 
LEADRasterView1.AutoRepaint = True

3.

Run your page to test it.