views:

71

answers:

1

Is there a way I can set an Alpha value that affects all subsequent GDI/GDI+ calls? in other words, I am looking to set the transparency for all calls on a Graphics object.

(I'm looking for something similar to how the *Transform functions affect the Graphics object they are called on)

+1  A: 

Unless there's something I'm not aware of, there's no facility in GDI for accomplishing this. Are you looking for some way to change the relative alpha values of all of the colors used in drawing in a GDI context? I don't think anything like that exists.

A better idea might be to cache your colors in your own custom repository, then when you want to set a global (or scope-wide) alpha value, you can use that to manipulate those colors. Obviously if I had more information I could probably come up with a solution that's more appropriate to your environment, but that's all I can offer just based on what's provided in the question.

Edit

After reading your comment, my suggestion would be to turn your painting code into a function that takes a Graphics object, a location/size (and whatever else is appropriate, if it isn't already this way) and a transparency float (ranging from 0 - 1.0). You can then create your colors in your function based upon the supplied transparency value.

Adam Robinson
I have code which draws some shapes on being given a Graphics object. I would like to reuse the same code to paint a semi-transparent overlay during a drag-and-drop. I was hoping to do something like g->Transparency = 0.5f... :)
Vulcan Eager