Need overlapping button in round cornered Winform

230 views Asked by At

Need a quick suggestion for styling a WinForm. I made it with rounded corners even when re-sized. Now trying to add a close button with a image (ControlBox=false), overlapping or clipped to top right corner. This is what I could end with.

My Attempt

But I wish to make it more like in this example image.

Example

How could I achieve this in WinForm.

2

There are 2 answers

0
Rakshith Ravi On BEST ANSWER

Here's the trick : your window doesn't just end with the white part. It extends a little bit further. The close button comes under the 'extra' part. The other sides where the window appears to not be there is actually transparent...or in the case of the image, semi-transparent.
The glow effect is provided by the window. Set the TransparencyKey property of the window to Color.Magenta (its a convention as Magenta is the color least likely to be used in a window). Then set the background image to a white background with a little bit of Magenta in the edges. The Magenta will appear transparent when set as the background image.
Fiddle around with TransparencyKey and you'll understand what I mean

0
Schwarzie2478 On

Winforms itself cannot provide this for you without outside manipulation of the windows,

because it still uses win32 windows classes in the background.

If you want transparancy in windows: see articles like:

Cool, Semi-transparent and Shaped Dialogs with Standard Controls

And the method in Win32 to do it: SetLayeredWindowAttributes