Results 1 to 8 of 8

Thread: Non Transparent form art on transparent form

  1. #1

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

    Post

    Hi everyone,
    I've been through all the info I can find in VB-World on transparent forms,but still come up short. I've got line art being drawn on my form.I want it to be transparent except for the line art so the user can change the background color using a form below it.Is this possible to do with vb?
    If not how did they do it in paint? I tryed to iterate through the points to change the colors and it took over 5 minutes!
    Any help is help.Thanks ahead of time.
    Joey o.

  2. #2

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

    Post

    Forgot to add: When I use the form transparent code from vb-tips my line art is not a control so it disapears with the form.

  3. #3
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    put the background picture on the form, but make the Form1.BackColor be great pink (255,0,255). then put this code is a .bas file:

    Code:
    Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
    Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
    Declare Function SetWindowRgn Lib "user32" (ByVal hwnd As Long, ByVal hRgn As Long, ByVal bRedraw As Long) As Long
    Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
    
         
    Sub FormLoad(frm As Form)
    
        Dim maskcolor As Long       'declare variable for the transparent color
        
        'set transparent color as great pink
        maskcolor = RGB(255, 0, 255)
        
        'perform function to make windows transparent
        TransBack 0, 0, frm.Width / 15, frm.Height / 15, maskcolor, frm.hdc, frm.hwnd
    
    End Sub
         
    Sub FormUnload()
    
        DeleteObject rgn    'clean up before closing
    
    End Sub
         
    Private Sub TransBack(ByVal xstart As Long, ByVal ystart As Long, ByVal xend As Long, ByVal yend As Long, ByVal bgcolor As Long, ByVal thdc As Long, ByVal thWnd As Long)
        
        'declare region variables
        Dim rgn2 As Long, rgn3 As Long, rgn4 As Long
        
        'declare substitute variables for the function parameters
        Dim Top As Long, Left As Long, Right As Long, Bottom As Long, temptop As Long
        
        'create some region buffers
        rgn = CreateRectRgn(0, 0, 0, 0)
        rgn2 = CreateRectRgn(0, 0, 0, 0)
        rgn3 = CreateRectRgn(0, 0, 0, 0)
        
        'this loop picks out the transparent colors,
        'there MUST be three loops or Windows has a hard
        'time handling the complex regions
    
        Left = xstart
        Right = (xend - xstart) + 1: Bottom = (yend - ystart) + 1
        
        Do While Left < Right  'go through and scan left to right
            Top = ystart
            Do While Top < Bottom  'go through and scan top to botom
                If GetPixel(thdc, Left, Top) <> bgcolor Then
                    temptop = Top
                    Do While GetPixel(thdc, Left, Top + 1) <> bgcolor
                        Top = Top + 1
                        If Top = Bottom Then Exit Do
                    Loop
                    rgn4 = CreateRectRgn(Left, temptop, Left + 1, Top + 1)
                    CombineRgn rgn3, rgn2, rgn2, 5
                    CombineRgn rgn2, rgn4, rgn3, 2
                    DeleteObject rgn4
                End If
                Top = Top + 1
            Loop
            CombineRgn rgn3, rgn, rgn, 5
            CombineRgn rgn, rgn2, rgn3, 2
            DoEvents
            Left = Left + 1
        Loop
    
        DeleteObject rgn2
        SetWindowRgn thWnd, rgn, True
        
    End Sub
    (obviously because it's what you're making ransparent) use a form for the next two proceedures.

    in the Form_Load place this code:

    Code:
    FormLoad Me
    when you unload the form, use the Form_Unload sub and put this code in there:
    Code:
    FormUnload
    if you want to make a different color transparent other than Great Pink just chakge the maskcolor = RGB(###,###,###) to the color you want transparent, then make that the Form1.BackColor

    [This message has been edited by funkheads (edited 12-06-1999).]

  4. #4

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

    Post

    I tested the above code by putting this into the mousemove event(among other things):

    PSet (x, y), QBColor((Rnd * 7) + 8)

    Then I put this code in the commandbutton_click event:

    maskcolor = QBColor((Rnd * 7) + 8)
    backcolor = maskcolor

    It doesn't work for me. The drawing still goes away when the new color is selected.Am I doing something wrong? If anyone knows please help. I've been trying to make this work for quite some time now and I would like get on with my life.
    thanks

  5. #5
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Post

    Try setting the forms AutoRedraw property to true.

  6. #6

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

    Post

    Tryed setting redraw to true - still no luck.

  7. #7
    Lively Member
    Join Date
    Nov 1999
    Posts
    98

    Post

    the only thing i can think that might be wrong is that you are not keping in mind that the "maskcolor" has to be in RGB form (red 0-255, green 0-255, blue 0-255) in the format ###,###,###. that's all i can see that you are doing wrong. other than that i don't know how else to help you. sorry...

    --michael

  8. #8

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

    Post

    Thanks for all the help so far!You've been great!I'll keep tryin'. Maybe I made a misprint or something simple.
    Thanks again

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