Hey all.
I have a whiteboard type program.
I have 2 picturebox's (needed for their mousemove/mousedown events)
Picture1.Picture = MyPicture
' Here is my hidden picture used to replace (on erase) Picture1
Picture2.Picture = MyPicture
Picture2.Enable = False
Both load the same picture, but one is hidden.
When one draws on Picture1, all is well.
When they erase when they draw, basically it copies the X/Y from
Picture2, and puts it back on Picture1.
I have some code to do this. works well, however it seems to carry alot of
overhead.
Sometimes the program blows out completly when erasing with a large 'brush
size'
Is there a more effecient way of doing this other than the way I am?
The code I have for this is the following:
' ----------------------------------------------------------------
' Start Code
'
' General Declarations
Private Declare Function GetPixel Lib "gdi32" _
(ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private MyBrushSize As Long
Private Sub Picture1_MouseDown _
(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Right-Click is Erase
If Button = 2 Then
MyBrushSize = 2
If BrushSize(0).Value = True Then MyBrushSize = 3
If BrushSize(1).Value = True Then MyBrushSize = 5
If BrushSize(2).Value = True Then MyBrushSize = 10
Call PenErase(X, Y, MyBrushSize)
End If
End Sub
Private Sub Picture1_MouseMove _
(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Right-Click is Erase
If Button = 2 Then
MyBrushSize = 3
If BrushSize(0).Value = True Then MyBrushSize = 3
If BrushSize(1).Value = True Then MyBrushSize = 5
If BrushSize(2).Value = True Then MyBrushSize = 10
Call PenErase(X, Y, MyBrushSize)
End If
End Sub
Private Sub PenErase(X As Single, Y As Single, Optional width As Long)
Dim MyX As Single, MyY As Single
Dim maxXy As Integer
Dim OldWidth As Long
OldWidth = Picture1.DrawWidth
Picture1.DrawWidth = 1
If width Then
maxXy = width
Else
' I have 3 options for brush sizes
If BrushSize(0).Value = True Then maxXy = 3
If BrushSize(1).Value = True Then maxXy = 5
If BrushSize(2).Value = True Then maxXy = 10
End If
Picture1.PSet (X, Y), GetPixel(Picture2.hdc, X, Y)
For MyY = 1 To maxXy
Picture1.PSet (X, Y + MyY), GetPixel(Picture2.hdc, X, Y + MyY)
Picture1.PSet (X, Y - MyY), GetPixel(Picture2.hdc, X, Y - MyY)
For MyX = 1 To maxXy
Picture1.PSet (X - MyX, Y), GetPixel(Picture2.hdc, X - MyX, Y) '
Picture1.PSet (X - MyX, Y - MyY), GetPixel(Picture2.hdc, X -
MyX, Y - MyY)
Picture1.PSet (X + MyX, Y - MyY), GetPixel(Picture2.hdc, X +
MyX, Y - MyY)
Picture1.PSet (X + MyX, Y), GetPixel(Picture2.hdc, X + MyX, Y)
Picture1.PSet (X + MyX, Y + MyY), GetPixel(Picture2.hdc, X +
MyX, Y + MyY)
Picture1.PSet (X - MyX, Y + MyY), GetPixel(Picture2.hdc, X -
MyX, Y + MyY)
Next MyX
Next MyY
Picture1.DrawWidth = OldWidth
End Sub
' End Code
' ----------------------------------------------------------------
Any help would be appreciated. Thanks :c)