Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi sir, this is hemanth, im struck up with one task nearly one month. please help me. How do I... Resize an image along with picturebox while resize the screen resolution in different screen lengths. I have a web page. in that i have panel control. an image along with picturebox placed in that panel. so i want to resize that image along with picturebox while resizing the windows form. i tried some code. but it is not resizing the image.. it is cutting he image as per screen size. so, please help me in this context.
Here is my code.
Imports System.Drawing.Drawing2D
Public Class Class1
Dim f_HeightRatio As Double
Dim f_WidthRatio As Double
Public Sub ResizeForm(ObjForm As Form, DesignerHeight As Integer, DesignerWidth As Integer)

'#region Code for Resizing and Font Change According to Resolution
'Specify Here the Resolution Y component in which this form is designed
'For Example if the Form is Designed at 800 * 600 Resolution then DesignerHeight=600
Dim i_StandardHeight As Integer = DesignerHeight
'Specify Here the Resolution X component in which this form is designed
'For Example if the Form is Designed at 800 * 600 Resolution then DesignerWidth=800
Dim i_StandardWidth As Integer = DesignerWidth
Dim i_PresentHeight As Integer = Screen.PrimaryScreen.Bounds.Height 'Present Resolution Height
Dim i_PresentWidth As Integer = Screen.PrimaryScreen.Bounds.Width 'Presnet Resolution Width
f_HeightRatio = CType((CType(i_PresentHeight / CType(i_StandardHeight, Double), Single)), Single)
f_WidthRatio = CType((CType(i_PresentWidth / CType(i_StandardWidth, Double), Single)), Single)
ObjForm.AutoScaleMode = AutoScaleMode.None 'Make the Autoscale Mode=None
If ObjForm.Name = "" Or ObjForm.Name = "Form1" Then
ObjForm.Scale(New SizeF(f_WidthRatio, f_HeightRatio))
End If
Dim c As Control
MsgBox(ObjForm.Name)

For Each c In ObjForm.Controls
MsgBox("Control " & c.Name.ToString)
MsgBox("Height of the control is " & c.Height)
MsgBox("Width of the control is " & c.Width)
If (c.HasChildren) Then
ResizeControlStore(c)
Else
c.Font = New Font(c.Font.FontFamily, c.Font.Size * f_HeightRatio, c.Font.Style, c.Font.Unit, (CType((0), Byte)))
End If
Next

ObjForm.Font = New Font(ObjForm.Font.FontFamily, ObjForm.Font.Size * f_HeightRatio, ObjForm.Font.Style, ObjForm.Font.Unit, (CType((0), Byte)))
'#End Region
End Sub
Public Sub ResizeControlStore(objCtl As Control)
MsgBox(objCtl.Name)
'MsgBox("Height of the control is " & objCtl.Height)
'MsgBox("Width of the control is " & objCtl.Width)

If objCtl.HasChildren Then

Dim cChildren As Control
For Each cChildren In objCtl.Controls
If (cChildren.HasChildren) Then
ResizeControlStore(cChildren)
Else
'If cChildren.Contains Is Text Then

If TypeOf (cChildren) Is PictureBox Then
MsgBox("PictureBox Identified")
Dim img As New PictureBox
With img
.Height = cChildren.Size.Height
.Width = cChildren.Size.Width
End With
img.Name = cChildren.Name.ToString
MsgBox(img.Name)
MsgBox("cChildren picturebox width" & cChildren.Size.Width)
MsgBox("cChildren picturebox Height" & cChildren.Size.Height)
'img.Image.Size = New Image(img.Image.Size(20, 20))
MsgBox("Img picture box width " & img.Size.Width)
MsgBox("Img picture box height" & img.Size.Height)

If Not img.Image Is Nothing Then
MsgBox("Reduce the size of Font")
cChildren.Font = New Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, (CType((0), Byte)))
Else
MsgBox("Reduce the size of the Image")
'cChildren.Size = New Size(cChildren.Size.Width * f_WidthRatio, cChildren.Size.Height * f_HeightRatio)
'img.Size = New Size(img.InitialImage.Size.Width * f_WidthRatio, img.InitialImage.Size.Height * f_HeightRatio)
MsgBox("Initial Img Image Height " & img.InitialImage.Size.Height)
MsgBox("Initial Img Image width " & img.InitialImage.Size.Width)
Dim bm_dest As Bitmap = New Bitmap(CInt(img.InitialImage.Width * f_WidthRatio), CInt(img.InitialImage.Height * f_HeightRatio))
MsgBox("resized Bitmap image width" & bm_dest.Size.Width)
MsgBox("resized Bitmap image Height" & bm_dest.Size.Height)
img.Size = New Size(img.Size.Width * f_WidthRatio, img.Size.Height * f_HeightRatio)
img.Image = bm_dest
MsgBox("Resized Img Image Height " & img.Image.Size.Height)
MsgBox("Resized Img Image width " & img.Image.Size.Width)
cChildren.Size = New Size(cChildren.Size.Width * f_WidthRatio, cChildren.Size.Height * f_HeightRatio)
MsgBox("resized cChildren picturebox width" & cChildren.Size.Width)
MsgBox("resized cChildren picturebox Height" & cChildren.Size.Height)
cChildren.Name = img.Name.ToString

End If
End If
cChildren.Font = New Font(cChildren.Font.FontFamily, cChildren.Font.Size * f_HeightRatio, cChildren.Font.Style, cChildren.Font.Unit, (CType((0), Byte)))

End If

Thanks in advance
hemanth
Posted

1 solution

See my answer in how to change image bitmap dimensions?[^], which may help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900