我在VB6里,放置了很多個picture控制元件,用來表示一些圖形,但是現在有多個picture控制元件,我的form長和寬有限,我現在將多個picture控制元件直接放在form上,當form運行時,有些picture是擋住了,看不到,想用滾動條來看到所有的picture控制元件,請問如何解決?
uj5u.com熱心網友回復:
要自己處理控制元件位置的,比如可以全放到一個Frame里,然后調整Frame的位置uj5u.com熱心網友回復:
新產生的picture的坐標位置包括寬度和高度,我都是計算可以得到,frame里如何放?如何產生滾動條uj5u.com熱心網友回復:
怎么在運行時拖動控制元件知道嗎?只能給你個簡單的例子自己看一下,剩下來的自己想吧,滾動條好看難看也是個煩心事
'表單上加一個Frame1控制元件
Private mx As Single
Private my As Single
Private Sub Frame1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
mx = X
my = Y
End If
End Sub
Private Sub Frame1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Frame1.Left = Frame1.Left + (X - mx)
Frame1.Top = Frame1.Top + (Y - my)
End If
End Sub
uj5u.com熱心網友回復:
我的代碼這樣:現在顯示出來效果,但是當里面盒子數超過表單的高度時,沒有滾動條,表單里放入一個picturebox控制元件,并且index設定成0,命名成pict代碼如下:
Dim numBox As Integer '每行顯示的盒子數
Dim leftStart, topStart, HSpace, VSpace, WBox, HBox As Integer 'x,y起點;水平和垂直間距
Dim oriTop As Integer 'y方向初始坐標值
Dim x_pos, y_pos As Integer '當前x,y的值
Private Sub Form_Load()
CreatePictArray
ListBox
End Sub
Private Sub CreatePictArray()
Dim i As Integer
For i = 1 To 400
Load pict(i)
pict(i).Width = 800
pict(i).Height = 800
pict(i).Visible = False
Next
pict(0).Visible = False
End Sub
Private Sub ListBox()
numBox = 8
leftStart = 200
topStart = 200
oriTop = 200
HSpace = 40
VSpace = 40
WBox = 800
HBox = 800
Dim i As Integer
For i = 1 To 60
If i Mod numBox = 0 Then
x_pos = leftStart + ((i Mod numBox) + numBox - 1) * (WBox + HSpace)
y_pos = topStart
pict(i).Visible = True
pict(i).Left = x_pos
pict(i).Top = y_pos
pict(i).Picture = LoadPicture("xxx.jpg")
topStart = (i / numBox) * (HBox + VSpace) + oriTop
Else
pict(i).Visible = True
x_pos = leftStart + ((i Mod numBox) - 1) * (WBox + HSpace)
y_pos = topStart
pict(i).Left = x_pos
pict(i).Top = y_pos
pict(i).Picture = LoadPicture("c:\xxx.jpg")
End If
Next i
End Sub
uj5u.com熱心網友回復:
你試一下這個,運行時候拖動一下pict試試
Private mx As Single, my As Single
Private numBox As Integer '每行顯示的盒子數
Private leftStart, topStart, HSpace, VSpace, WBox, HBox As Integer 'x,y起點;水平和垂直間距
Private Sub Form_Load()
numBox = 8
leftStart = 200
topStart = 200
HSpace = 40
VSpace = 40
WBox = 800
HBox = 800
CreatePictArray 400
ListBox
End Sub
Private Sub CreatePictArray(ByVal Count As Integer)
Dim I As Integer
For I = 0 To Count - 1
If I > pict.UBound Then Load pict(I)
pict(I).Move leftsrart, topStart, WBox, HBox
pict(I).Visible = True
'===============
pict(I).AutoRedraw = True
pict(I).Print I
'===============
Next
End Sub
Private Sub ListBox()
Dim xPos As Single, yPos As Single
For I = 0 To pict.UBound
xPos = leftStart + (I Mod numBox) * (WBox + HSpace)
yPos = topStart + (I \ numBox) * (HBox + VSpace)
If (xPos + (WBox + HSpace) > 0) And (yPos + (HBox + VSpace) > 0) And (xPos + (WBox + HSpace) < Me.ScaleWidth) And (yPos + (HBox + VSpace) < Me.ScaleHeight) Then
pict(I).Move xPos, yPos
pict(I).Visible = True
Else
pict(I).Visible = False
End If
Next
End Sub
Private Sub Form_Resize()
If Me.WindowState = 1 Then Exit Sub
ListBox
End Sub
Private Sub pict_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
mx = X
my = Y
End If
End Sub
Private Sub pict_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
'leftStart = leftStart + (X - mx)'不想水平方向移動就把這條注釋掉
topStart = topStart + (Y - my)
ListBox
End If
End Sub
uj5u.com熱心網友回復:
看這個帖子的15樓,這是滾動一個圖的。多個圖原理也一樣,都是坐標偏移 (-HScroll1.Value, -VScroll1.Value)。
uj5u.com熱心網友回復:
http://www.m5home.com/bak_blog2/article/125.html好老的代碼了,給你參考吧
uj5u.com熱心網友回復:
又見故人!老馬你好啊
你壓縮包里的美女真不錯呀!!!!!!!!!!!!!!!
uj5u.com熱心網友回復:
阿勇好啊!好久不見!就知道有人會說美女!哈哈
uj5u.com熱心網友回復:
計算位置,然后移動!uj5u.com熱心網友回復:
美女!
uj5u.com熱心網友回復:
簡單點:用個msflexgrid,設成單列,每行一格, 各自加載圖片即可轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/109531.html
標籤:控件
