VB中的Picture控件问题
VB中的Picture控件,可以显示滚动条吗,我想在picture控件中画点画圆,但是如果画得比这个控件大小还大,有一部分就看不到了,请问如何能上picture显示出滚动...
VB中的Picture控件,可以显示滚动条吗,我想在picture控件中画点画圆,但是如果画得比这个控件大小还大,有一部分就看不到了,请问如何能上picture显示出滚动条
展开
4个回答
展开全部
加个滚动条,滚动条是改变窗体风格加的,你可以把用于打印的picture放入另一个picture里,可以通过改变这个父控件picture风格添加滚动条,这样独立性更好一些,比如可以随意调整父控件picture的相对位置及尺寸信息。另外,打印之前必须开辟足够的高度,否则将无法显示打印内容。至于如何设定picture高度,那是你自己的事(建议API获得字符字高行间距等信息),以下是滚动条代码,你参考下吧:
'新建窗体,添加picture1
'以下保存在模块中:
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
Public Const GWL_STYLE = (-16)
Public Const WS_VSCROLL = &H200000
Public Const GWL_WNDPROC = (-4)
Public Const SB_VERT = 1
Public Const WM_VSCROLL = &H115
Public Const WM_MOUSEWHEEL = &H20A
Public Const WM_SIZE = &H5
Public Const SB_LINEDOWN = 1
Public Const SB_LINELEFT = 0
Public Const SB_PAGEDOWN = 3
Public Const SB_PAGEUP = 2
Public Const SB_THUMBTRACK = 5
Public winold As Long, winnew As Long, stlold As Long, stlnew As Long, ymax As Double, ypos As Double
Public Function mywinproc(ByVal hwnd As Long, ByVal umsg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
Select Case umsg
Case WM_VSCROLL '垂直滚动条消息
Select Case wparam Mod &H10000 '取低位
Case SB_LINEUP, SB_LINEDOWN '滚动条smallchange
ypos = IIf(wparam, ypos + 5, ypos - 5)
Case SB_PAGEUP, SB_PAGEDOWN '滚动条largechange
ypos = IIf(wparam = 2, ypos - 10, ypos + 10)
Case SB_THUMBTRACK '拖动滑块
ypos = (wparam And &HFFFF0000) / &H10000 '取高位
End Select
If ypos < 0 Then ypos = 0
If ypos > ymax Then ypos = ymax
SetScrollPos hwnd, SB_VERT, ypos, True '设置滚动条value
Form1.Picture1.Top = -ypos
Case WM_MOUSEWHEEL '鼠标滚轮消息
If ymax > 0 Then '不能全部显示picture1的高度
ypos = IIf(Sgn(wparam) > 0, ypos - 50, ypos + 50)
If ypos < 0 Then ypos = 0
If ypos > ymax Then ypos = ymax
SetScrollPos hwnd, SB_VERT, ypos, True '设置滚动条value
Form1.Picture1.Top = -ypos
End If
Case WM_SIZE
ymax = (Form1.Picture1.Height - Form1.Height / 15 + 33) '重新计算滚动条范围
If ymax > 0 Then '不能全部显示picture1的高度
SetScrollRange hwnd, SB_VERT, 0, ymax, True '设置滚动条value范围
If Form1.Picture1.Top < -ymax Then ypos = ymax '如果picture1.top超过滚动条调节上限,重新调整picture1.top
ShowScrollBar hwnd, SB_VERT, True '显示滚动条
Else
ShowScrollBar hwnd, SB_VERT, False '隐藏滚动条
End If
SetScrollPos hwnd, SB_VERT, ypos, True
Form1.Picture1.Top = -ypos
End Select
mywinproc = CallWindowProc(winold, hwnd, umsg, wparam, lparam)
End Function
'以下保存在窗体中:
Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.AutoRedraw = True
Picture1.Move 0, 0, Me.Width / 15 - 24
Picture1.Height = 12030
Picture1.Print "我是一个picture,打印前请先给我开辟足够的高度"
For i = 1 To 1000
Picture1.Print i
Next
Picture1.Print "——结束"
stlold = GetWindowLong(hwnd, GWL_STYLE) '取得旧风格
stlnew = stlold Or WS_VSCROLL '新风格在旧风格基础上加入垂直滚动条
SetWindowLong hwnd, GWL_STYLE, stlnew '设置新风格
winold = GetWindowLong(hwnd, GWL_WNDPROC) '取得旧窗体函数
winnew = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf mywinproc) '设置新窗体函数
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong hwnd, GWL_WNDPROC, winold '还原窗体过程函数
End Sub
'新建窗体,添加picture1
'以下保存在模块中:
Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
Public Const GWL_STYLE = (-16)
Public Const WS_VSCROLL = &H200000
Public Const GWL_WNDPROC = (-4)
Public Const SB_VERT = 1
Public Const WM_VSCROLL = &H115
Public Const WM_MOUSEWHEEL = &H20A
Public Const WM_SIZE = &H5
Public Const SB_LINEDOWN = 1
Public Const SB_LINELEFT = 0
Public Const SB_PAGEDOWN = 3
Public Const SB_PAGEUP = 2
Public Const SB_THUMBTRACK = 5
Public winold As Long, winnew As Long, stlold As Long, stlnew As Long, ymax As Double, ypos As Double
Public Function mywinproc(ByVal hwnd As Long, ByVal umsg As Long, ByVal wparam As Long, ByVal lparam As Long) As Long
Select Case umsg
Case WM_VSCROLL '垂直滚动条消息
Select Case wparam Mod &H10000 '取低位
Case SB_LINEUP, SB_LINEDOWN '滚动条smallchange
ypos = IIf(wparam, ypos + 5, ypos - 5)
Case SB_PAGEUP, SB_PAGEDOWN '滚动条largechange
ypos = IIf(wparam = 2, ypos - 10, ypos + 10)
Case SB_THUMBTRACK '拖动滑块
ypos = (wparam And &HFFFF0000) / &H10000 '取高位
End Select
If ypos < 0 Then ypos = 0
If ypos > ymax Then ypos = ymax
SetScrollPos hwnd, SB_VERT, ypos, True '设置滚动条value
Form1.Picture1.Top = -ypos
Case WM_MOUSEWHEEL '鼠标滚轮消息
If ymax > 0 Then '不能全部显示picture1的高度
ypos = IIf(Sgn(wparam) > 0, ypos - 50, ypos + 50)
If ypos < 0 Then ypos = 0
If ypos > ymax Then ypos = ymax
SetScrollPos hwnd, SB_VERT, ypos, True '设置滚动条value
Form1.Picture1.Top = -ypos
End If
Case WM_SIZE
ymax = (Form1.Picture1.Height - Form1.Height / 15 + 33) '重新计算滚动条范围
If ymax > 0 Then '不能全部显示picture1的高度
SetScrollRange hwnd, SB_VERT, 0, ymax, True '设置滚动条value范围
If Form1.Picture1.Top < -ymax Then ypos = ymax '如果picture1.top超过滚动条调节上限,重新调整picture1.top
ShowScrollBar hwnd, SB_VERT, True '显示滚动条
Else
ShowScrollBar hwnd, SB_VERT, False '隐藏滚动条
End If
SetScrollPos hwnd, SB_VERT, ypos, True
Form1.Picture1.Top = -ypos
End Select
mywinproc = CallWindowProc(winold, hwnd, umsg, wparam, lparam)
End Function
'以下保存在窗体中:
Private Sub Form_Load()
Me.ScaleMode = 3
Picture1.AutoRedraw = True
Picture1.Move 0, 0, Me.Width / 15 - 24
Picture1.Height = 12030
Picture1.Print "我是一个picture,打印前请先给我开辟足够的高度"
For i = 1 To 1000
Picture1.Print i
Next
Picture1.Print "——结束"
stlold = GetWindowLong(hwnd, GWL_STYLE) '取得旧风格
stlnew = stlold Or WS_VSCROLL '新风格在旧风格基础上加入垂直滚动条
SetWindowLong hwnd, GWL_STYLE, stlnew '设置新风格
winold = GetWindowLong(hwnd, GWL_WNDPROC) '取得旧窗体函数
winnew = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf mywinproc) '设置新窗体函数
End Sub
Private Sub Form_Unload(Cancel As Integer)
SetWindowLong hwnd, GWL_WNDPROC, winold '还原窗体过程函数
End Sub
展开全部
Picture控件是不自带滚动条的,但楼主可以把picture控件的AutoSize属性值设置为True,这样,picture控件就会根据图形的大小来自动调节自己的大小。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
不能加入滚动条,可以改自动大小
picture1.autosize=ture
picture1.autosize=ture
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
控件可以形成控件数组
使用方法和数组一样,通过控件数组名+下标来访问控制
你那个可以说是一个控件数组
根据括号内的位运算来确定是控件数组内的哪个控件可见或不可见
比如括号内运算后值为1
Picture1(1).Visible
=
True
就说明名为Picture的控件数组内Index为1的可见性为真
分拿来
使用方法和数组一样,通过控件数组名+下标来访问控制
你那个可以说是一个控件数组
根据括号内的位运算来确定是控件数组内的哪个控件可见或不可见
比如括号内运算后值为1
Picture1(1).Visible
=
True
就说明名为Picture的控件数组内Index为1的可见性为真
分拿来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询