I am trying to make a simple game. Using C# forms and picturebox

[IMG]http://img52.imageshack.us/img52/8696/bgproblem.jpg[/IMG]

but when I set transparent on the character,
it goes through the form (I can see part of my desktop, instead of white space)

:The character can move when I press direction keys, the character picture and background is in PNG format


any solutions or other options?

Recommended Answers

All 7 Replies

I think the problem is the actual picture you can easily open up paint and import the picture and make the background black so it blends with your background on your game
then for the yellow part you will need to do it carefully so it does not look uneven

Or if you have photoshop you can use the magnetic tool to cut it out and that will get rid of all the white and will blend in without having to add any colours

You shouldn't be having a problem with transparency going through the form...

Goto into your graphics package and give it a Transparent background and import it to your picture box making sure you select the correct image format.

Otherwise, pick a non-widely used colour (like that fluorescent pink colour) and set your picture box transparency colour to the same.

Be aware, the transparency in C# forms is not true transparency. It will apply the background image/colour of the controls parent. You wont be able to see other controls through the control on top.

The image of another ImageBox is not used when determining what to paint for transparent images. As Ryshad pointed out it is the background of the parent control that is used.

Rather than put the background image in a picturebox, either

  • Set the forms background to your background image.
    OR
  • Use a Panel and make your character's imagebox a member of the panel's controls collection. (i.e. place it in the panel)

If you just need to see the background through your transparent sections of the picturebox then, as nick said, you need the picturebox to be a child control of the container that hosts your background image.
If you want to be able to overlap images and have each image visible in the transparent sections then you wont be able to use standard form controls. Either manually paint each image in a single Paint event, or consider something like Managed DirectX or XNA

do you have example for Managed DirectX. this is my first time to do it 2d graphics

Ive never worked with it i'm afraid. There may be sample code on the msdn website

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.