INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Please need help with picture box inside group box aspect ratio

Please need help with picture box inside group box aspect ratio

(OP)
Hi, I am having a bit of a problem here, this is my form (I have a picture box inside the group box)
and the problem I am having is when I expand the box the picture does not expand with the box
but stays the same size, i am trying to make it expand/collapase with the box. I Would really
appreciate help on this. :(
Here is my code:
Public Class Form1
Inherits System.Windows.Forms.Form
Dim miDesignWidth, miDesignHeight As Integer
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
Friend WithEvents picPhoto As System.Windows.Forms.PictureBox
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.picPhoto = New System.Windows.Forms.PictureBox
Me.Button1 = New System.Windows.Forms.Button
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
Me.SuspendLayout()
'
'picPhoto
'
Me.picPhoto.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.picPhoto.Location = New System.Drawing.Point(64, 40)
Me.picPhoto.Name = "picPhoto"
Me.picPhoto.Size = New System.Drawing.Size(264, 176)
Me.picPhoto.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
Me.picPhoto.TabIndex = 0
Me.picPhoto.TabStop = False
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(152, 248)
Me.Button1.Name = "Button1"
Me.Button1.Size = New System.Drawing.Size(96, 32)
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(448, 341)
Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.picPhoto)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If OpenFileDialog1.ShowDialog() = DialogResult.OK Then
picPhoto.Image = Image.FromFile(OpenFileDialog1.FileName)
End If
Dim piWidth, piHeight As Integer
Dim piTemp As Integer
picPhoto.SizeMode = PictureBoxSizeMode.AutoSize
piWidth = picPhoto.Width
piHeight = picPhoto.Height
If (piWidth <= miDesignWidth) And (piHeight <= miDesignHeight) Then
'place it with proper spacing to the edges.
ElseIf (piWidth > miDesignWidth) And (piHeight <= miDesignHeight) Then
' fit to width and adjust height for aspect ratio
piTemp = piWidth
piWidth = miDesignWidth
piHeight = CInt(piHeight * piWidth / piTemp)
ElseIf (piWidth <= miDesignWidth) And (piHeight > miDesignHeight) Then
' fit to height and adjust width for aspect ratio
piTemp = piHeight
piHeight = miDesignHeight
piWidth = CInt(piWidth * piHeight / piTemp)
Else
If (piHeight / piWidth) <= (miDesignHeight / miDesignWidth) Then
' fit to width and adjust height for aspect ratio
piTemp = piWidth
piWidth = miDesignWidth
piHeight = CInt(piHeight * piWidth / piTemp)
Else
' fit to height and adjust width for aspect ratio
piTemp = piHeight
piHeight = miDesignHeight
piWidth = CInt(piWidth * piHeight / piTemp)
End If
End If
picPhoto.SizeMode = PictureBoxSizeMode.Normal
picPhoto.Width = piWidth
picPhoto.Height = piHeight
picPhoto.SizeMode = PictureBoxSizeMode.StretchImage
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
miDesignWidth = picPhoto.Width
miDesignHeight = picPhoto.Height
End Sub
End Class

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close