Transparency of shaped forms?

V

vBOT

Hi all,

I have an odd shaped graphic I would like to use as my interface (see it
here at http://www.mokee.com/vbot/ver3/face.jpg) The part I want to be
transparent on the image is red. I set the background image of my form to
be this image (actually a transparent png version), then I set the
transparency key to red as well. Instead of the shaped form I thought I
would have, I now have the graphic with a white border as my form.

Is there a way to get this transparent? I see the fact that VS.Net has some
transparency issues being discussed around the net. If I set some
components to red bg, they are transparent, but not the silly background
image! Has anyone found an easy fix for this? Sorry if this has been
answered, but I just could not find a solution that actually worked for
me...

Thanks in advance!
 
V

vBOT


Erik,

Thanks for the link! I tried to add the .cs file into my own project,
but it's giving me a headache. It keeps telling me I can't call the
convert routine as a static. I've been using Delphi for years and
switching to C# is a bit confusing. Think I need to do some more
learning about the correct structure of classes within the namespace
before I tackle this. Hate being a newbie again...
 
E

Erik Frey

Your project is probably in a different namespace, so to access the
BitmapToRegion class (as it is defined in its .cs file) you have to refer to
it within its BitmapToRegion namespace (a little confusing):

this.Region = BitmapToRegion.BitmapToRegion.Convert( bm, col,
TransparencyMode.ColorKeyTransparent );

or, just move the class (and the enum it uses) into one of your own
namespaces. However your project is structured.

Also, because the code is unsafe, you will probably want to put the
BitmapToRegion class in its own project (create a new class library and call
it Graphics, perhaps), then you must edit the project settings ->
configuration properties -> Allow Unsafe Code Blocks -> True.

Hope that helps,

Erik
 
V

vBOT

Your project is probably in a different namespace, so to access
the
BitmapToRegion class (as it is defined in its .cs file) you have to
refer to it within its BitmapToRegion namespace (a little confusing):

this.Region = BitmapToRegion.BitmapToRegion.Convert( bm, col,
TransparencyMode.ColorKeyTransparent );

or, just move the class (and the enum it uses) into one of your
own
namespaces. However your project is structured.

Also, because the code is unsafe, you will probably want to put
the
BitmapToRegion class in its own project (create a new class library
and call it Graphics, perhaps), then you must edit the project
settings -> configuration properties -> Allow Unsafe Code Blocks ->
True.

Hope that helps,

Erik

It does help greatly - thanks! In the end, however, I found a great
reference on Bob Powell's site:

http://www.bobpowell.net/region_from_bitmap.htm

I took his idea and changed it a bit to apply to my project and it works
brilliantly. I can now programmatically create new forms and change
their shape as needed through a hidden main form. And without the use of
"unsafe code", which makes me feel a bit better.

The more I program and discover things in csharp, the more I like it!
 
E

Erik Frey

Cool! You're right - this is a more comfortable implementation. Thanks
for the link.
 

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