Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sizing a form to a PictureBox

Status
Not open for further replies.

jjhobs

Instructor
Sep 18, 2003
27
GB
I have an MDI form with a menu that allows a user to open an image. The image is then placed into a PictureBox control on a child form. The Autosize property of the PictureBox is set to true. The child form is then made visible. When the child form appears I want it to be the same size as the PictureBox. I thought this would be very easy, but everything I try is unsuccessful. Any help would be greatly appreciated.
Thanks
JJ
 
Don't know what you've tried but I would first move the picture box to the upper left corner of the form and then set the form's height & width with

pic1.Move 0, 0
Me.Height = pic1.Height
Me.Width = pic1.Width
Me.Refresh

in the Form_Activate Event. Works on SDI ... haven't tried on MDI.
 
if you set the picture boxes left and top properties to 0 then do something like the following after loading the picture.

Form1.Width = Picture1.Width
Form1.Height = Picture1.Height + (Form1.Height - Form1.ScaleHeight)
 
Thanks to you both for your quick response. I am still having problems, but wonder whether it is because I have changed the scalemode of the picturebox and form to 3-pixel. Thanks anyway for your help.
 

Ok, this worked for me but please note that I left the scalemode at twips. Also there is no code in form1.
[tt]
Option Explicit

Sub Main()

Load Form1
Form1.Picture1.Picture = LoadPicture("F:\z\01.jpg")
Form1.Picture1.Move 0, 0
Form1.AutoRedraw = True
Form1.Picture1.Refresh

Form1.Width = Form1.Picture1.Width + 90
Form1.Height = Form1.Picture1.Height + 360

Form1.Show

End Sub
[/tt]

As you can see I had to add to the width and height of the form to get the entire picture to show and to give it an equal border around the picture. I think the piece that is probably missing from your code to get it to work is the...
[tt]
Form1.Picture1.Refresh
[/tt]
Also note that both the AutoRedraw and AutoSize are set to true.

Good Luck

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top