2 Attachment(s)
shaped sub-form inside mdicontainer
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());
http://www.codeguru.com/forum/attach...id=15840&stc=1
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());
http://www.codeguru.com/forum/attach...id=15841&stc=1
How do I make the sub-form appear as a shaped form inside of the mdicotainer form?
I referenced this article... http://www.codeproject.com/dotnet/GraphicalForms.asp
Re: shaped sub-form inside mdicontainer
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.
Shaped Windows Forms and Controls in Visual Studio .NET
- petter
Re: shaped sub-form inside mdicontainer
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?
Re: shaped sub-form inside mdicontainer
there's an article that talks about that. it basically creates the path based on the bitmap image. http://www.codeproject.com/csharp/bmprgnform.asp
Re: shaped sub-form inside mdicontainer
I also found a good sample right here on codeguru... http://codeguru.earthweb.com/csharp/...cle.php/c4259/
Re: shaped sub-form inside mdicontainer
same type of thing, only much faster...
good find.
Re: shaped sub-form inside mdicontainer
FYI...
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.
Quote:
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.
Re: shaped sub-form inside mdicontainer
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.