I have a parent form that houses multiple sub-forms. I have set the TransparencyKey of the sub-form to {128,255,128}. Then I created a bitmap image that will be used as the BackGroundImage of the sub-form. I filled the exterior of the image with {128,255,128}. This should give the shaped subform effect.
If I create the sub-form stand alone, then I get the desired effect and the sub-form is shaped.
Code:
Application.Run(new frmSubForm());
However, if I run the mdiform and then create a sub-form inside of the parent, the sub-form is no longer shaped.
Code:
Application.Run(new frmMdiContainer());
How do I make the sub-form appear as a shaped form inside of the mdicotainer form?
To make a window 'shaped' you can use the Form.Region property (or Win32 APIs SetWindowRgn) . This should work for both top level windows and MDI children.
So how to I create a GraphicsPath object with the same contout as my desired shape? Obviously, the bitmap is self is square, by definition, but the shape within the bitmap is what I want to use as my window region. See my predicament?
I implemented both samples in my code. I found the codeguru sample to be much MUCH faster.
Here is the explanation (taken from the codeguru article) as to why the codeguru version performs faster.
This algorithm obviously involves going through every individual pixel of the provided bitmap. Unfortunately, the GetPixel method of the Bitmap class is awfully slow. The other way to gain access to the bitmap's pixels is through the LockBits method. This method returns a BitmapData object containing a pointer to the top left pixel of the bitmap.
Yes, I did say pointer. While you usually program using safe references instead of raw pointers, C# lets you use C-style pointers in special sections of code marked as unsafe. The fact that these sections have to be explicitly labeled, and that you have to add the /unsafe switch to the compiler to make them compile, goes a long way in showing that this is not something MS intends you to use on a regular basis. However, there are circumstances under which their use can be justified. I believe this is one of those circumstances.
a while back I had to write an app that merged a bunch of regions in seperate images into a single bitmap, and found out that doing it unmanaged (while its still clunky and not very graceful IMO) is hands down the faster option.
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.