我如何...在调整不同屏幕长度的屏幕分辨率的同时调整图像和图片框的大小 [英] How do I... Resize an image along with picturebox while resize the screen resolution in different screen lengths
问题描述
先生,这是hemanth,我接近一个月的任务。请帮我。我如何...在调整不同屏幕长度的屏幕分辨率的同时调整图像和图片框的大小。我有一个网页。因为我有面板控制。图像以及放置在该面板中的图片框。所以我想在调整窗体大小的同时调整图像和图片框的大小。我尝试了一些代码。但它没有调整图像的大小..它根据屏幕尺寸切割图像。所以,请在这方面帮助我。
这是我的代码。
Imports System.Drawing.Drawing2D
公共类Class1
Dim f_HeightRatio As Double
Dim f_WidthRatio As Double
Public Sub ResizeForm(ObjForm As Form,DesignerHeight As Integer,DesignerWidth as Integer)
'#region根据分辨率调整大小和字体更改的代码
'在此指定此表单设计的分辨率Y组件
'例如,如果表格设计为800 * 600分辨率,则DesignerHeight = 600
Dim i_StandardHeight As Integer = DesignerHeight
'在此处指定分辨率X组件此表单设计
'例如,如果表单设计为800 * 600分辨率,那么DesignerWidth = 800
Dim i_StandardWidth As Integer = DesignerWidth
Dim i_PresentHeight As Integer = Screen.PrimaryScreen.Bounds.Height'当前分辨率高度
Dim i_PresentWidth As Integer = Screen.PrimaryScreen.Bounds.Width'Presnet Resolution Width
f_HeightRatio = CType( (CType(i_PresentHeight / CType(i_StandardHeight,Double),Single)),单个)
f_WidthRatio = CType((CType(i_PresentWidth / CType(i_StandardWidth,Double),Single)),单()) />
ObjForm.AutoScaleMode = AutoScaleMode.None'使自动缩放模式=无
如果ObjForm.Name =或ObjForm.Name =Form1那么
ObjForm.Scale(New SizeF(f_WidthRatio,f_HeightRatio))
结束如果
Dim c As Control
MsgBox(ObjForm.Name)
每个c在ObjForm.Controls中
MsgBox(Control&c.Name.ToString)
MsgBox(控件的高度为&c.Height)
MsgBox(宽度 e控制是&c.Width
如果(c.HasChildren)那么
ResizeControlStore(c)
否则
c.Font = New Font(c.Font.FontFamily,c.Font.Size * f_HeightRatio,c.Font.Style,c.Font.Unit,(CType((0),Byte)))
结束如果
下一页
ObjForm.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(控件的高度为&objCtl.Height )
'MsgBox(控件的宽度是&objCtl.Width)
如果objCtl.HasChildren那么
Dim cChildren作为控制
每个cChildren在objCtl.Contro ls
if(cChildren.HasChildren)那么
ResizeControlStore(cChildren)
否则
'如果cChildren.Contains是文本然后
如果TypeOf(cChildren)是PictureBox那么
MsgBox(PictureBox识别)
Dim img As New PictureBox
with img
.Height = cChildren.Size.Height
.Width = cChildren.Size.Width
结束
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 =新图片(img.Image.Size(20,20))
MsgBox(Img图片框宽度&img.Size.Width)
MsgBox(Img图片框高度&img.Size.Height)
如果不是img.Image则什么都没有
MsgBox (减小字体大小)
cChildren.Font =新字体(cChildren.Font.FontFamily,cChildren.Font.Size * f_HeightRatio,cChildren.Font.Style,cChildren.Font.Unit, (CType((0),Byte)))
Else
MsgBox(缩小图像大小)
'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(初始图像高度和img.InitialImage.Size.Height)
MsgBox(初始图像宽度和img.InitialImage.Size.Width)
Dim bm_dest As Bitmap = New Bitmap(CInt(img.InitialImage.Width * f_WidthRatio),CInt(img.InitialImage.Height * f_HeightRatio))
MsgBox(调整大小的位图图像width&bm_dest.Size.Width
MsgBox(调整大小的位图图像高度&bm_dest.Size.Height)
img.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 =新大小(cChildren.Size.Width * f_WidthRatio,cChildren.Size.Height * f_HeightRatio)
MsgBox(调整大小的cChildren图片框宽度&cChildren.Size.Width)
MsgBox(resized cChildren picturebox Height&cChildren.Size.Height)
cChildren.Name = img.Name.ToString
End如果
结束如果
cChildren.Font =新字体(cChildren.Font.FontFamily,cChildren.Font.Size * f_HeightRatio,cChildren.Font.Style,cChildren.Font。单位,(CType((0),Byte)))
结束如果
提前致谢
hemanth
在如何更改图像位图尺寸? [ ^ ],这可能会对您有所帮助。
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
See my answer in how to change image bitmap dimensions?[^], which may help you.
这篇关于我如何...在调整不同屏幕长度的屏幕分辨率的同时调整图像和图片框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!