CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315

    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());


    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?

    I referenced this article... http://www.codeproject.com/dotnet/GraphicalForms.asp
    Attached Images Attached Images

  2. #2
    Join Date
    Apr 2005
    Location
    Norway
    Posts
    3,934

    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

  3. #3
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315

    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?

  4. #4
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    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

  5. #5
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315

    Re: shaped sub-form inside mdicontainer

    I also found a good sample right here on codeguru... http://codeguru.earthweb.com/csharp/...cle.php/c4259/

  6. #6
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    Re: shaped sub-form inside mdicontainer

    same type of thing, only much faster...

    good find.

  7. #7
    Join Date
    May 2003
    Location
    Corvallis, OR
    Posts
    315

    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.

    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.

  8. #8
    Join Date
    Mar 2004
    Location
    33°11'18.10"N 96°45'20.28"W
    Posts
    1,808

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured