Erasing on Transparent form

algebra

Newcomer
Joined
May 24, 2009
Messages
3
Hi all,


I'm trying to build a simple drawing application which would allow people to drawing on their screen. The application makes use of a maximum form which is transparent, which allows people to optionally annotate items that exist behind the application.


For the most part, it seems to work fine. I am able to use DrawLine to draw lines on the form. Now, i want to be able to provide a way to erase random portions of the screen using a eraser. However, I can't seem to figure out the best way to actually do that.


Drawing with a transparent Pen doesn't achieve this. Drawing with a pen that has the same color as the TransparencyKey of the form just draws a line with the same color as the TransparencyKey (it doesn't make that line "transparent").

Second problem is we need to make drawing line with a semi-transparent (like a felt-tip marker). But when we set alpha color value to 128, the line is not semi-transparent, but the color that same color as the TransparencyKey show up too.

Anyone have any thoughts on this?
please help me.

thanks
 
I don't know a solution, but I would be very interested in knowing how you have created what you have to date.

I'd like to put something like that into our BETA releases under the Suggestions and Bugs report tool.
 
Have you tried setting the Graphics.CompositingMode to CompositingMode.SourceCopy and drawing with Color.Transparent (or a Pen with said color)? The SourceCopy mode specifies that transparency should overwrite the existing pixel data rather than blending with it.

Of course this all depends on how you've achieved transparency. There is the pseudo-transparent route (copy a screen image, paste it on your form, then draw on top of that), you could use regions, a transparency key, or layered windows. The correct solution depends on your approach.
 
hi all,
thanks for replied my problems. actually i have already tried to using CompositingMode.SourceCopy, but the result is not solving my problem. i use layered form to make transparent. because i need to get real time dekstop background, if i use region or copy a screen image to my form its not my purpose.

i attach solution for little code to make you understand our problem, this code cut from my project.

hopefully people on extremedonettalk.com could give me a solution for my problem.

thanks.
 

Attachments

Here are my findings:

I think that this line is killing you:
Code:
                [COLOR="Blue"]using [/COLOR](Graphics gr = [COLOR="Blue"]this[/COLOR].CreateGraphics())
The problem is probably creating a Graphics object on a HWnd for a layered window. GDI+ probably isn't really designed with layered windows in mind, and things seem to be getting hairy when the Graphics object acts directly on the HWnd.

I tried creating a Bitmap with the dimensions of the Form and initializing it to transparent, then setting it to the Form's background. Then I did all the drawing with a Graphics object created on the Bitmap. To erase, I used a transparent Pen with the compositing mode set to SourceCopy. Using this method, both drawing and erasing worked properly.

The problem is that, when using a background image, you need to invalidate the form every time the image changes (i.e. every time you draw anything), and the performance hit is very painful. But that should get you going in the right direction.


Another problem you have is that your external Windows API declarations aren't right. When I first tried to run the app I kept getting stack imbalance issues and had to correct same of the definitions.
 
Here. It's not very usable in its current form, and I didn't correct all the P/Invoke signatures, just those that threw exceptions. Also, there is some extraneous stuff in there from my tinkering around; the important stuff is what I highlighted above.
 

Attachments

Hi,

I have application for Pocket PC. I ran it into treo 700w emulator This application works with othet pocket pc emulator . i got the problem when i closing the form screen will not refresh. it seems to be hanged.

please help me in this regard why it will happen?

Thanks
Sohail
 
Back
Top