Jump to content

Overlapping pictureboxes?

- - - - -

  • Please log in to reply
12 replies to this topic

#1
justanothernoob

justanothernoob

    Newbie

  • Members
  • PipPip
  • 22 posts
I am making a game, but I can't figure out how to put one image over the other. The background of the front image, covers up the picturebox under it.

For example, I have two fish images, but when one is in front of the other, its background covers up the other fish.

I attached a picture as an example of the problem. What's the easiest way to fix this?

Thanks.

Attached Files



#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
The easiest way to do this is, to just open the fish image up in GIMP or PS, and make the background transparent.
~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#3
justanothernoob

justanothernoob

    Newbie

  • Members
  • PipPip
  • 22 posts
Thanks for the reply. I did make the background transparent in those fish images, and that's what happens. The background in the front image is transparent just in that it shows the form color. If i changed the form to red, it would have a red background.

My problem is I don't know how to show the back picture through the front picture's background.

I know this can be done in WPF, but I'm sure there is a way to do it in WinForms, I'm pretty sure I've seen it done before.


This is what I want it to look like (done in paint lol):

Attached Files



#4
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
i havent done this type of thing in a long time.. and maybe not even with .NET.

But you used to be able to set a transparent color,
in your image, any parts that were that color wouldn't be rendered.

#5
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
Hmm im not sure how you could do this, since whenever you set the background color to transparent it always becomes the the background of its container, in this case the Form.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#6
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
I think what Sam is talking about is, the Transparency-Key properties which you can set on Form to make certain colors transparent. Only problem with that is, it makes the whole Form transparent wherever that color is found. So if you set the color to lime green, and it finds the lime green around the fish picture, its going to make all the green around the fish completely transparent revealing anything behind the Form, which I dont think is what your looking for.

~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.

#7
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
yeah, it's all coming back to me now.
it was a way to make 'rounded' forms, by removing the form border, control box, and setting a background image on the form, with the transperancy key,
as well as a few other settings, you could make the whole form appear to be drag-able, rounded, and nice looking. (not different from say how, winamp looks)

my bad

#8
justanothernoob

justanothernoob

    Newbie

  • Members
  • PipPip
  • 22 posts
So would this work to make the back picturebox appear in the background of the front picturebox or does it just work with the form?

#9
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
I'm gonna try a few things here, standby

#10
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
Ok, so I took a look at this, and tried to answer your specific question. I'm not sure. I tried creating images with transparent backgrounds, and the control itself (the picturebox) still shows the border.

A couple of solutions might be to use WPF controls in a container on your form. I'd tend to steer away from that myself.

Another might be to draw the images to the form, which isn't as difficult as it seems. It's just you're going to be kicking some things into manual gear.

A third option. might be to use managed direct x or something. Though, that's a bit out of my area of expertise. =)

I can give you some example code of how this manual drawing might look if you like...

#11
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
Ok, so I have an attachment, a stupid project I made in about 3 minutes.. sorry, it illustrates the point..:c-cool:

[ATTACH]3735[/ATTACH]

so, run it, and it will draw 2 fairly large overlapping png images, and it will load a small one called orb (the green dot)

you can tap the Up, down, left, right arrows to move that orb around

I could show you some more advanced techniques to get rid of some jitter, or to make it more natural.

Anyways, have fun!

Attached Files



#12
justanothernoob

justanothernoob

    Newbie

  • Members
  • PipPip
  • 22 posts
Thanks so much sam_coder. This helps a lot, but I'm disappointed that I won't be able to use the images I drew lol.

I guess I will switch to using WPF for projects like these, I just like the coding in WinForms so much better :/




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users