Transparent GIF in a transparent container. Easy right?!?!?!

M

Mark Deibert

I'm a former VB6 coder. Quit a few years ago. Now I'm back and trying
to teach myself VB.NET. I don't remember having this much difficulty
learning VB6. I'm totally stuck on something and need your expert
guidance.

I just want to load a GIF with a transparent background into a
container with a transparent background. So I can move the GIFs over
and under each other. You know, as in basic game stuff. I can load the
transparent GIF no prob, I just -cannot- get any container to have a
transparent background. Yes, I have looked at all the seemingly
obvious container properties. I've set and reset them to
color.transparent and etc. with no luck. I've set the picbox
background to red, loaded the GIF and I can see thru the GIF to the
red background. I know the GIF isn't the problem.

This seems so silly/simple/basic I can't understand why I haven't
found any examples. Perhaps my search words are suspect. Not sure. Can
someone please post the three or four lines of code and/or steps
necessary to do this?

Thank you, thank you, thank you, thank you for your help,

Mark :)
 
F

Fergus Cooney

Hi Mark,

It is amazingly easy to do what you want. - if you use .NET's WinApi-ish
overrides.

I say easy, not 'cos I've done it, but because I've read the article - and
the juicy bit is only a few lines long.

Bob Powell's the man who knows.
http://www.bobpowell.net/transcontrols.htm

Regards,
Fergus
 
M

Mark Deibert

It is amazingly easy to do what you want. - if you use .NET's WinApi-ish
overrides.

I say easy, not 'cos I've done it, but because I've read the article - and
the juicy bit is only a few lines long.

Bob Powell's the man who knows.
http://www.bobpowell.net/transcontrols.htm

Wow, so I'm actually not a moron. Read through Bob's example. I had no
idea it would be so tough. Let me ask a quick follow up question. Can
I load, display, and move a GIF around on the main form without
putting it in a container? In other words, is the container necessary?

Thanks for replying Fergus.

Mark :)
 
F

Fergus Cooney

Hi Mark,

Let's be pedantic first. A gif is a file format which will be transformed
into a bitmap. A bitmap is just that - a block of bits, although a .NET Bitmap
is a bit more, but still just a fancy data structure. Nothing new to you, I
reckon - you were just hoping it might be different. When it comes to the
screen we need Windowy things which a Bitmap doesn't have.

So, yes, you do need the container - because that's the one that knows a
thing or two about being visible.

Now, let's get a bit more useful, perhaps - but I'm only guessing from the
use of that word 'game'

I imagine that you want to have several sprites dancing around. You could
do it with each sprite fitting neatly inside its own container, and I'm no
expert so this may be the best way. But you could also do it with a couple or
several game arena sized 'layers' and have more than one sprite on that layer.
This would be best suited for static images, but it may be useful even with
moving images depending on what, and how, and when's tea.

The Graphics of a container can be drawn on at any point and within given
bounds, so you are not just restricted to loading a gif into a PictureBox. You
can load an image into a Bitmap (which will just be a dumb resource waiting to
be used) and then copy it or parts of it into your 'layer' as required.

Now I guess, I sound like I know what I'm talking about ;-) but I haven't
done this. I've seen it done and know enough bits and pieces to give you a
thirst for more. But when you start asking me for more details, I'll start
umming and aahing.

But I will suggest making friends with Graphics.DrawImage as this has
loads of overloads. If it's not enough for what you want, though, you can
still use the WinApi BitBlt. The .NET declaration is below.

Have fun.

Regards,
Fergus

Public Declare Function BitBlt Lib "gdi32" ( _
ByVal hDestDC As IntPtr, _
ByVal x As Integer, _
ByVal y As Integer, _
ByVal nWidth As Integer, _
ByVal nHeight As Integer, _
ByVal hSrcDC As IntPtr, _
ByVal xSrc As Integer, _
ByVal ySrc As Integer, _
ByVal dwRop As Integer _
) As Integer

Const SRCCOPY As Integer = &HCC0020
 
M

Mark Deibert

Bob Powells example on how to make a transparent control is in C#.
Helps a bit but not enough.

I definitely appreciate your words of wisdom. I'll see what I can
learn about using DrawImage. I'll also be very happy when I find some
VB.NET code which accomplishes what Bob talks about in his transparent
control C# example.

Mark :)
 
J

Jeff Bennett

I'm a former VB6 coder. Quit a few years ago. Now I'm back and trying
to teach myself VB.NET. I don't remember having this much difficulty
learning VB6. I'm totally stuck on something and need your expert
guidance.

I just want to load a GIF with a transparent background into a
container with a transparent background. So I can move the GIFs over
and under each other. You know, as in basic game stuff. I can load the
transparent GIF no prob, I just -cannot- get any container to have a
transparent background. Yes, I have looked at all the seemingly
obvious container properties. I've set and reset them to
color.transparent and etc. with no luck. I've set the picbox
background to red, loaded the GIF and I can see thru the GIF to the
red background. I know the GIF isn't the problem.

This seems so silly/simple/basic I can't understand why I haven't
found any examples. Perhaps my search words are suspect. Not sure. Can
someone please post the three or four lines of code and/or steps
necessary to do this?

Thank you, thank you, thank you, thank you for your help,

Mark :)


Mark - if you are still struggling here, let me know if you would
consider using a commercial component. Our MetaDraw control (
available for either VB 6 or .NET Winforms ) will allow you to have
one or multiple transparent GIF's within a container which itself has
a transparent background ( you can even scroll, zoom, draw upon, and
print the container plus lots more )

Write to me by e-mail if you are interested.
I'd be happy to answer any questions and get you
started with evaluation
Please include a copy of this message with your reply.


Jeff Bennett
(e-mail address removed)

Bennet-Tec Information Systems, Inc
50 Jericho Tpk, Jericho, NY 11753
Phone 516 997 5596, Fax - 5597
WWW.Bennet-Tec.Com

RELIABLE Component Software
and Software Development Services
* TList/Pro * ALLText HT/Pro * MetaDraw *

====================== ======================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top