C# – How to make a part of the form partially transparent in C#

c++transparencywinforms

I want to make a part of a form semi-transparent, with additional text on that part which is not transparent.

How can I accomplish this in C#?

Best Solution

I don't think you can apply transparency (more correctly termed, Opacity) to only a part of a form rather than the complete, whole form.

You can, however, create a custom shaped form (i.e. non-rectangular) quite easily, with various parts of that form being transparent. Depending upon the exact "look" that you're trying to achieve, this may be closest you'll get.

Take a look at these links for creating your own custom-shaped form:

Creating Custom Shaped Windows Forms in .NET
Custom shaped form with a drop down in C#
Shaped Windows Forms and Controls in Visual Studio .NET

The only other alternative may be to display two forms, one of which is set to be partially transparent. You would have to programmatically ensure that the second form is positioned immediately next to the "main" form, and is moved/resized proportionately when the user moves/resizes the "main" form. Although this is two forms, it could be made to look, to the user, that it's actually only one form, although this could be quite tricky to pull off, and would not be a perfect solution (but may be "good enough" depending upon your exact needs).