Hallo Grisu786,
Refresh brauchst du nur einmal. Sieh dir mal dieses Beispiel an:
'Controls: keine
Option Explicit
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function Polygon Lib "gdi32" (ByVal hdc As Long, lpPoint As _
POINTAPI, ByVal nCount As Long) As Long
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As _
Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal _
hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As _
Long
Private WithEvents Cmd1 As CommandButton
Private Pic1 As PictureBox, Pic2() As PictureBox, Pic3 As PictureBox
Private SW%, SH%
Private Sub Form_Load()
Dim Figur(3) As POINTAPI, i%, j%
SW = 64
SH = 64
Randomize
Me.ScaleMode = vbPixels
Me.WindowState = vbMaximized
Set Cmd1 = Me.Controls.Add("Vb.CommandButton", "C1")
With Cmd1
.Move 2 * SW + 100, 16
.Caption = "Aufbau"
.Visible = True
End With
For i = 1 To 4
With Figur(i - 1)
.x = Choose(i, SW / 2 - 1, SW - 2, SW / 2 - 1, 0)
.y = Choose(i, 0, SH / 2 - 1, SH - 1 - 1, SH / 2 - 1)
End With
Next i
ReDim Pic2(5)
For i = 0 To 5
Set Pic2(i) = Me.Controls.Add("Vb.PictureBox", "Feld" & CStr(i))
With Pic2(i)
.ScaleMode = vbPixels
.BorderStyle = vbBSNone
.Move 4, 4 + (SW + 4) * i, SW, SH
.BackColor = vbBlack
.ForeColor = .FillColor
.FillColor = QBColor(11 - i)
.FillStyle = vbFSSolid
.AutoRedraw = True
Call Polygon(.hdc, Figur(0), 4)
.Visible = True
End With
Next i
Set Pic1 = Me.Controls.Add("Vb.PictureBox", "P1")
With Pic1
.ScaleMode = vbPixels
.Move 8 + SW, 8 + SH, 500, 400
.AutoRedraw = True
.Visible = True
End With
Set Pic3 = Me.Controls.Add("Vb.PictureBox", "P3")
With Pic3
.ScaleMode = vbPixels
.BorderStyle = vbBSNone
.Move 8 + SW, 4, SW, SH
.BackColor = vbWhite
.ForeColor = vbWhite
.FillColor = vbBlack
.FillStyle = vbFSSolid
.AutoRedraw = True
Call Polygon(.hdc, Figur(0), 4)
.Visible = True
End With
End Sub
Private Sub Cmd1_Click()
'Aufbau der Grafik
Dim i%, j%, n%, XPos&, YPos&
Dim P1hdc&, P3hdc&
P3hdc = Pic3.hdc
With Pic1
P1hdc = .hdc
For j = 0 To .ScaleHeight / (SH / 2) - 2
For i = 0 To .ScaleWidth / SW - 2
n = Int(Rnd * 6) ' zufällige Grafik auswählen
XPos = i * 64 + 32 * (j And 1)
YPos = j * SH / 2
' And mit Maske
Call BitBlt(P1hdc, XPos, YPos, SW, SH, P3hdc, 0, 0, vbSrcAnd)
' Bild mit Or zeichnen
Call BitBlt(P1hdc, XPos, YPos, SW, SH, Pic2(n).hdc, 0, 0, vbSrcPaint)
Next i
Next j
.Refresh
End With
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim i%
Me.Controls.Remove Cmd1
Me.Controls.Remove Pic1
Me.Controls.Remove Pic3
For i = 0 To 5
Me.Controls.Remove Pic2(i)
Set Pic2(i) = Nothing
Next i
Set Pic1 = Nothing
Set Pic3 = Nothing
Set Cmd1 = Nothing
End SubGruss,
Zardoz |