Tranparent color... - Page 2
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 20 of 20

Thread: Tranparent color...

  1. #16
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    Re: Tranparent color...

    Post what you have so far, and we'll see if it is a problem or not...
    Code:
    ' Use CODE TAGS
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  2. #17
    Join Date
    Jul 2005
    Location
    Quebec, Canada
    Posts
    72

    Post Re: Tranparent color...

    I posted it above but here it is again. This code makes a colour on a form totally transparent where you see through the form. I want the exact same effect but this time, you see throught the control like shown in the pictures above.

    Code:
    Private Declare Function SetWindowLongptr Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
    Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
    
    Private Const GWL_EXSTYLE = (-20) ' Transparent color
    Private Const GWL_STYLE = (-16) ' Expandable borders
    Private Const WS_EX_LAYERED = &H80000
    Private Const WS_EX_TRANSPARENT = &H20
    Private Const WS_EX_APPWINDOW = &H40000
    Private Const LWA_ALPHA = &H2
    Private Const LWA_COLORKEY = &H1
    Private Const COL_TRANS = &HFF     ' Transparent Red
    
    Private Sub Form_Load()
    
      Dim Alpha As Byte
      Dim MaskColour As Long
    
      Alpha = 200
      MaskColour = COL_TRANS
      
      ' Whatever control you want to make the backcolor transparent
      ' Set the backcolor to the transparent color
      Picture1.BackColor = MaskColour
      Option1.BackColor = MaskColour
      Check1.BackColor = MaskColour
      Me.BackColor = MaskColour
      Text1.BackColor = MaskColour
      Command1.BackColor = MaskColour
      
      ' Apply Transparency
      SetWindowLongptr Me.hwnd, GWL_EXSTYLE, WS_EX_LAYERED Or WS_EX_APPWINDOW
      SetLayeredWindowAttributes Me.hwnd, MaskColour, Alpha, LWA_COLORKEY ' Or LWA_ALPHA
      
    End Sub
    David Richard

  3. #18
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,990

    Re: Tranparent color...

    Take a look at my code, and use F8 to step thru it line by line as you move the slider.


    Me, in the case below, refers to FORM1.ME (shorthand). If you want Picture1 to blend, then use Picture1.hWnd to vary the blend.

    Code:
    Private Sub sldAlpha_Change()
        Dim bAlpha          As Byte
        
        bAlpha = CByte(sldAlpha.Value)
        
        ' Set the new alpha level
        SetLayeredWindowAttributes Me.hWnd, 0&, bAlpha, LWA_ALPHA
        
        Me.Refresh
    End Sub
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #19
    Join Date
    Apr 2009
    Posts
    394

    Re: Tranparent color...

    Yesterday, I found/modified code that did nearly exactly what you wanted except that the area of the picture box you could click through. Meaning that the form did not recieve any mousemove or click events. Also as part of this description, if the picture boxes zorder=0 then it would also bore holes through any control behind it and in reverse, other controls would hide portions of the picturebox so you would get a funny shaped hole in your form.

    I searched several sites yesterday in hopes of answering your question, and the best I can come up with is that user control or use a seperate form for your effect.

    However, if you find another way, please post the code.

    Thanks and Good Luck

  5. #20
    Join Date
    Jul 2005
    Location
    Quebec, Canada
    Posts
    72

    Cool Re: Tranparent color...

    I have tried everything that you guys posted here and I got no solution. It IS indeed a hard thing to do and find on the net. Before posting here, I searched a lot on Internet and tried to find a way to do this.

    I did not want to use a UserControl because of all then hassle of programming it's parameters to set up the effect I wanted but it seems impossible for now to have the effect wanted with a simple PictureBox.

    I want to thank everyone who has tried to help at its best to find a solution to this problem. I'm probably sure that this post will be way back in pages after this but at least, if it's contents can help someone else than at least no-one help for nothing.

    Thanks again to everyone.

    David Richard
    David Richard

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center