CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2001
    Location
    Alabama
    Posts
    1

    Borderless and Transparent?

    I'm stumped. How can I do a borderless and tansparent control that also responds to both left and right mouse click? I have a bitmap for my form, and I don't want to see the control. I've tried many things, but have never been able to get it all together.

    Also, any ideas on how to limit the shape of a control to round when the control needs to also be a bitmap? I can't seem to get rid of the square background. Trying to specify a mask color only produces a gray background that is still square.

    Many Thanks!


  2. #2
    Join Date
    Mar 1999
    Location
    Nepal
    Posts
    540

    Re: Borderless and Transparent?

    In your form,
    place a picturebox and set its borderstyle to None.
    Set the autoredraw of both the form and the picturebox to True.
    Set the scalemode of both the picturebox and the form to pixel.

    Now, enter the following code:

    private Declare Function CreateEllipticRgn Lib "gdi32" (byval X1 as Long, byval Y1 as Long, byval X2 as Long, byval Y2 as Long) as Long
    private Declare Function SetWindowRgn Lib "user32" (byval hWnd as Long, byval hRgn as Long, byval bRedraw as Boolean) as Long
    private Declare Function BitBlt Lib "gdi32" (byval hDestDC as Long, byval x as Long, byval y as Long, byval nWidth as Long, byval nHeight as Long, byval hSrcDC as Long, byval xSrc as Long, byval ySrc as Long, byval dwRop as Long) as Long

    private Sub Command1_Click()
    Call BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Form1.hDC, Picture1.Left, Picture1.Top, vbSrcCopy)
    Call SetWindowRgn(Picture1.hWnd, CreateEllipticRgn(0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight), true)
    Picture1.Refresh
    End Sub




    What you have got is a round control, that doesn't show up, but responds to all events of the picturebox.

    Blt-ing the background on the picturebox gives it a transparent effect.
    SetWindowRgn can be used to shape any control or form (anything having a hWnd) to any shape (as long as we can create a region of that shape)


  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Borderless and Transparent?

    Go to Freevbcode.com and search for this item
    "Use a Bitmap to Create a Skinnable Irregular-Shaped Form". it shows a good example of "Skinning" a form.

    John G

  4. #4
    Join Date
    Jun 2002
    Location
    Pasadena, CA
    Posts
    11

    Form Shape

    I have used a product called TYPICAL_FormShaper. It allows you to make a form or a control any shape you wish with a couple of lines of code. I'd recommend it highly.

    www.typicalsoftware.com
    How Hard Could it Be?

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

Featured