| | |
Problem with Picture Box resizing
Please support our VB.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Jun 2008
Posts: 89
Reputation:
Solved Threads: 7
This may sounds stupid. I'm new to VB.net. My problem is that all the size of my picture box kept running.
1. I'm not sure is it because i set the form's backbgroundimagelayout to "Stretch" and all Picturebox's sizemode to "Stretch Image".
2. When i start my app on another pc (which has diff resolution), the picture box size will change automatically.
3. When i added something to my form, again.... Picturebox size change and overlap each other.
Suggestionss????
1. I'm not sure is it because i set the form's backbgroundimagelayout to "Stretch" and all Picturebox's sizemode to "Stretch Image".
2. When i start my app on another pc (which has diff resolution), the picture box size will change automatically.
3. When i added something to my form, again.... Picturebox size change and overlap each other.
Suggestionss????
•
•
Join Date: Feb 2008
Posts: 14
Reputation:
Solved Threads: 0
Try this code it should automatically resize ur pictures
•
•
•
•
Imports System.IO Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Public Sub AutosizeImage(ByVal ImagePath As String, ByVal picBox As PictureBox, Optional ByVal pSizeMode As PictureBoxSizeMode = PictureBoxSizeMode.CenterImage) Try picBox.Image = Nothing picBox.SizeMode = pSizeMode If System.IO.File.Exists(ImagePath) Then Dim imgOrg As Bitmap Dim imgShow As Bitmap Dim g As Graphics Dim divideBy, divideByH, divideByW As Double imgOrg = DirectCast(Bitmap.FromFile(ImagePath), Bitmap) divideByW = imgOrg.Width / picBox.Width divideByH = imgOrg.Height / picBox.Height If divideByW > 1 Or divideByH > 1 Then If divideByW > divideByH Then divideBy = divideByW Else divideBy = divideByH End If imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)) imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution) g = Graphics.FromImage(imgShow) g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel) g.Dispose() Else imgShow = New Bitmap(imgOrg.Width, imgOrg.Height) imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution) g = Graphics.FromImage(imgShow) g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel) g.Dispose() End If imgOrg.Dispose() picBox.Image = imgShow Else picBox.Image = Nothing End If Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
Last edited by densman; Apr 5th, 2009 at 8:33 am.
![]() |
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic beginner box button buttons click code combo component connectionstring convert cpu cuesent data database databasesearch datagrid datagridview datetimepicker design designer dissertation dissertations dissertationthesis dosconsolevb.net editvb.net exists firewall folder forms html image images isnumericfuntioncall listview math mobile module mssqlbackend mysql navigate number opacity open peertopeervideostreaming picturebox1 picturebox2 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left savedialog serial settings socket sqldatbase sqlserver storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio visualstudio.net web wpf wrapingcode xml





