请问怎么给图片框加滚动条以能看图片的不同部分。希望给出代码

csdnzhu 2003-08-25 12:28:41


我想用VB的图片框载入一个图片,可是当图片太大时,就只能显示一小部分,请问怎么给图片框加滚动条以能看图片的不同部分。希望给出代码
p
...全文
98 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
pigpag 2003-08-25
  • 打赏
  • 举报
回复
VB的书上都有的
射天狼 2003-08-25
  • 打赏
  • 举报
回复
Option Explicit

Private Sub Form_Load()
Picprint.AutoSize = True '加载图片的时候能自动调整大小
End Sub

'添加一个PictureBox控件,改名为:P,做为容器
'在P里再加一个PictureBox控件,改名为:Picprint,在这里显示图片
'在P里再加一个水平滚动条,改名为:Hs,加一个垂直滚动条,改名为:Vs
Private Sub Form_Resize()
On Error Resume Next
P.Width = Me.ScaleWidth
P.Left = 0
P.Top = 13.5
P.Height = Me.ScaleHeight - 13.5

Vs.Top = 0
Vs.Min = -10

If Picprint.Visible Then
If Picprint.Height > P.Height Then
Vs.Max = Picprint.Height - P.ScaleHeight + 15
Else
Vs.Max = P.Height - Picprint.Height + 15
End If
End If

Vs.Height = P.ScaleHeight - Hs.Height
Vs.Left = P.ScaleWidth - Vs.Width

Hs.Min = -10

If Picprint.Visible Then
If Picprint.Width > P.Width Then
Hs.Max = Picprint.Width - P.Width + 15
Else
Hs.Max = P.Width - Picprint.Width + 15
End If
End If

Hs.Top = P.ScaleHeight - Hs.Height
Hs.Width = P.ScaleWidth - Vs.Width

Hs.Left = 0

Picprint.Left = (P.Width - 250 - Picprint.Width) / 2
Picprint.Top = (P.Height - 250 - Picprint.Height) / 2

Hs_change
Vs_Change
End Sub

Private Sub Hs_change()
On Error Resume Next
If Picprint.Visible = False Then
Picprint.Left = -Hs.Value
Else
Picprint.Left = -Hs.Value
End If
End Sub

Private Sub Vs_Change()
On Error Resume Next
If Picprint.Visible = False Then
Picprint.Top = -Vs.Value
Else
Picprint.Top = -Vs.Value
End If
End Sub
Apple200228 2003-08-25
  • 打赏
  • 举报
回复
1 在From上添加两个picturebox,Picture1,Picture2,Picture1包含Picture2
Picture2.autosize=true
2 在From上添加HScroll1和VScroll1

Option Explicit
Private Sub Form_Resize()
On Error Resume Next
VScroll1.Max = Picture2.Height - Picture1.Height
VScroll1.Value = 0
Picture2.Lef = 0
VScroll1.Visible = IIf(VScroll1.Max > 0, ture, False)
HScroll1.Max = Picture2.Width - Picture1.Width
HScroll1.Value = 0
Picture2.Top = 0
HScroll1.Visible = IIf(HScroll1.Max > 0, True, False)
End Sub

Private Sub HScroll1_Change()
Picture2.Left = -HScroll1.Value
End Sub

Private Sub HScroll1_Scroll()
Picture2.Left = -HScroll1.Value
End Sub

Private Sub VScroll1_Change()
Picture2.Top = -VScroll1.Value
End Sub

Private Sub VScroll1_Scroll()
Picture2.Top = -VScroll1.Value
End Sub



liul17 2003-08-25
  • 打赏
  • 举报
回复
picturebox.autosize=true
若不能满足还可以用 Image 控件
image1.stretch=true可以实现缩放,若还不行只能用函数了。
道素 2003-08-25
  • 打赏
  • 举报
回复
Private Sub Form_Load()

Form1.ScaleMode = 6
Picture1.ScaleMode = 6
Picture2.AutoSize = True

Picture1.BorderStyle = 0
Picture2.BorderStyle = 0

Picture2.Picture = _
LoadPicture("f:\sign.jpg")

Picture1.Move 0, 0, ScaleWidth - VScroll1.Width, ScaleHeight - HScroll1.Height
Picture2.Move 0, 0

HScroll1.Top = Picture1.Height
HScroll1.Left = 0
HScroll1.Width = Picture1.Width

VScroll1.Top = 0
VScroll1.Left = Picture1.Width
VScroll1.Height = Picture1.Height

HScroll1.Max = Picture2.Width - Picture1.Width
VScroll1.Max = Picture2.Height - Picture1.Height

VScroll1.Visible = (Picture1.Height < Picture2.Height)
HScroll1.Visible = (Picture1.Width < Picture2.Width)

End Sub

Private Sub HScroll1_Change()
Picture2.Left = -HScroll1.Value
End Sub

Private Sub VScroll1_Change()
Picture2.Top = -VScroll1.Value
End Sub

Private Sub Form_Resize()
Picture1.Height = Form1.Height
Picture1.Width = Form1.Width
Picture1.Move 0, 0, ScaleWidth - VScroll1.Width, ScaleHeight - HScroll1.Height
Picture2.Move 0, 0
HScroll1.Top = Picture1.Height
HScroll1.Left = 0
HScroll1.Width = Picture1.Width
VScroll1.Top = 0
VScroll1.Left = Picture1.Width
VScroll1.Height = Picture1.Height
HScroll1.Max = Picture2.Width - Picture1.Width
VScroll1.Max = Picture2.Height - Picture1.Width

' Check to see if scroll bars are needed.
VScroll1.Visible = (Picture1.Height < Picture2.Height)
HScroll1.Visible = (Picture1.Width < Picture2.Width)

End Sub


如果经常用,你可以考虑做成一个类,我以前做了一个,找不到了,把两个picturebox和滚动条做为参数传递进去
我上边的例子滚动条在两个picturebox外边

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧