Results 1 to 5 of 5

Thread: Mr Young! Could you help?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post


    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


  2. #2
    So Unbanned DiGiTaIErRoR's Avatar
    Join Date
    Apr 1999
    Location
    /dev/null
    Posts
    4,111

    Post

    May I ask what you are trying to do?

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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    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.

  4. #4
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    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..
    Code:
    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
    [email protected]
    [email protected]


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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Post

    Thanks again Aaron!I'll let you know how it works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width