开发者

Changing the opacity of individual form controls in .NET

开发者 https://www.devze.com 2023-01-11 11:18 出处:网络
Ok, so what I\'m trying to do is have two imageb开发者_高级运维oxes overlapping so that I can align the images in them (based on user input). The problem is I\'m not sure if I can adjust the opacity o

Ok, so what I'm trying to do is have two imageb开发者_高级运维oxes overlapping so that I can align the images in them (based on user input). The problem is I'm not sure if I can adjust the opacity of individual controls so I can only see the topmost control. Of course, I could do image processing and combine the two images into a single image (with the appropriate transparency settings) but doing that on each input operation would be somewhat expensive so I figured doing it on the UI thread would be a lot cheaper.

Any suggestions? Thank you in advance.


This isn't possible in WinForms, transparency effects don't work for overlapping controls. The best you could do is overlapping forms so you can use the Opacity and TransparencyKey properties.

A far more practical approach is to use one PictureBox in which you display a composite image. Such an image is easy to create with the ColorMatrix class. You'll find sample code in my answer in this thread.


As @Kane says, wpf is probably better for this. Only the Form control supports Opacity as a property in winforms (see msdn), but you might be able to get away with it if you put your images in sub-forms (I'm really speculating here, haven't tried this.) and play with their opacity.

Good luck

0

精彩评论

暂无评论...
验证码 换一张
取 消