Results 1 to 4 of 4

Thread: Transparent panel background isn't really transparent...

  1. #1

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Transparent panel background isn't really transparent...

    Hello! I'm trying to make a scrolling shooter with a plane, but whenever the plane passes over a cloud or any other object, you can see the background is not transparent.

    I used a panel, and set the background images to the plane, clouds, and other things, and set the background color as "transparent." (The actual images have a transparent background too.) The background color of the form is blue. Most of the time it will look normal, but when 2 objects pass through each other, you can see the blue square on the front-most object.

    Anyway to make the background color actually transparent? Thanks in advance!

    Edit: I'm using VB 2010 Express.

  2. #2
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    5,984

    Re: Transparent panel background isn't really transparent...

    The short answer is to not use a control, but draw the image on your drawing surface.
    A transparent control is "transparent" by showing its container's contents below it. When you have overlapping controls, the container isn't directly "under" the control, so you have interference that isn't handled properly (as you would think it should work) by winforms.
    There should be at least one example in the Code Bank, I would assume, but I don't have one readily at hand and don't have time to look for one myself.

    Did a quick search and this, http://www.vbforums.com/showthread.p...-For-Beginners , is the first one I came across which could be useful in general.
    It covers various areas, but there is a pong game early on that uses a transparent png file for the ball image. I didn't look at the details, or the code, but that should be just one example of drawing objects with transparency that can be found in the code bank.
    Last edited by passel; Jul 20th, 2014 at 04:55 PM.

  3. #3

    Thread Starter
    Addicted Member NinjaNic's Avatar
    Join Date
    Dec 2013
    Location
    Earth
    Posts
    230

    Re: Transparent panel background isn't really transparent...

    Ok, thanks, and I really appreciate the help. But now I need to know how to set the location of the bitmap images, but there is no option in the intelli sense window for location, x, or y, and does not run if I manually type BitmapImage.Location=. It wasn't fully explained in the Pong thread.
    So my question is, how do I set the location of a bitmap? Thanks again.

  4. #4
    PowerPoster boops boops's Avatar
    Join Date
    Nov 2008
    Location
    Holland/France
    Posts
    3,115

    Re: Transparent panel background isn't really transparent...

    You set the X, Y position by using the arguments of the DrawImage instruction. For example, to draw an image at location (50,100) on Form1:
    Code:
    Private Sub Form1_Paint(Sender As Object, e As PaintEventArgs) Handles MyBase.Paint
         e.Graphics.DrawImage(myImage, 50, 100)
    End Sub
    If you want to resize the image, you can specify a width and height as well:
    Code:
    e.Graphics.DrawImage(myImage, 50, 100, 30, 30)
    There are many other variants (Overloads) of the DrawImage statement, which can make the Intellisense and the error messages a bit overwhelming at first. But as Passel advised, it's the best way to go for transparency with moving images.

    BB

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
  •  



Click Here to Expand Forum to Full Width