PDA

Click to See Complete Forum and Search --> : Mr Young! Could you help?


joey o.
Dec 13th, 1999, 09:11 AM
I can't give up! I need to know how to keep the dots from being erased when the command button is pushed in this code.all the "transparent form" code I've been trying still doesn't do it. Help!Help! Help!

Private Sub Command1_Click()
BackColor = QBColor((Rnd * 8) + 7)
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
DrawWidth = 7
PSet (X, Y)
End Sub

DiGiTaIErRoR
Dec 13th, 1999, 12:00 PM
May I ask what you are trying to do?

------------------
DiGiTaIErRoR

joey o.
Dec 13th, 1999, 09:12 PM
I'm trying to write a graphics program that draws lines to the form and has an option to change the background color while keeping the drawn lines visible.I've used this stripped naked example to show what has to be preserved while the backcolor is changed.
Thanks.

Aaron Young
Dec 14th, 1999, 02:57 AM
When you draw on a Form/Picturebox the Graphic isn't Persistent,
this means when you change the Backcolor/Update the Object, the Graphic will be lost.
You can make the Graphic Persistent by setting the Objects' AutoRedraw Property to True.
This creates another problem, as now the Entire Image is treated as a Graphic, (Background Included).

To change the Background color, you would need to create a Mask of your Drawn Image,
Which you could overlay onto a new Background.
This isn't particulary easy and takes quite a few API Calls..

If you're looking for a Quick Fix, you can utilize this functionality already built into the ImageList Control, eg.

Add a Picturebox, Command Button, CommonDialog and ImageList Control to a Form..

Private Sub Command1_Click()
On Error GoTo ColorErr
With CommonDialog1
.DialogTitle = "Select a Background Color.."
.CancelError = True
.ShowColor
'Copy Current Image to the ImageList
ImageList1.ListImages.Add , "PIC", Picture1.Image
'Set the MaskColor to the Current BackGround Color
ImageList1.MaskColor = Picture1.BackColor
'Change the Picturebox Back Color, Erasing the Image
Picture1.BackColor = .Color
'ReDraw the Original Image with a Transparent Background
ImageList1.ListImages("PIC").Draw Picture1.hDC, 0, 0, imlTransparent
'Remove the Image from the ImageList
ImageList1.ListImages.Remove ("PIC")
End With
ColorErr:
End Sub

Private Sub Form_Load()
Picture1.AutoRedraw = True
End Sub

Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then Picture1.PSet (X, Y)
End Sub

Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = vbLeftButton Then
Picture1.Line -(X, Y)
End If
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net


[This message has been edited by Aaron Young (edited 12-14-1999).]

joey o.
Dec 14th, 1999, 03:46 AM
Thanks again Aaron!I'll let you know how it works.