Click here to Skip to main content
15,887,746 members
Articles / Desktop Programming / Windows Forms

An Alpha Channel Composited Windows Form with Designer Support

Rate me:
Please Sign up or sign in to vote.
4.96/5 (124 votes)
5 Oct 2009CPOL8 min read 323.3K   48.8K   279  
An alpha channel composited form for image based Window frames
<html xmlns:MSHelp="http://msdn.microsoft.com/mshelp"><head><title>AlphaFormTransformer Class</title><link rel="stylesheet" type="text/css" href="../styles/presentation.css" /><link rel="stylesheet" type="text/css" href="ms-help://Hx/HxRuntime/HxLink.css" /><script type="text/javascript" src="../scripts/EventUtilities.js"></script><script type="text/javascript" src="../scripts/StyleUtilities.js"></script><script type="text/javascript" src="../scripts/SplitScreen.js"></script><script type="text/javascript" src="../scripts/ElementCollection.js"></script><script type="text/javascript" src="../scripts/MemberFilter.js"></script><script type="text/javascript" src="../scripts/CollapsibleSection.js"></script><script type="text/javascript" src="../scripts/LanguageFilter.js"></script><script type="text/javascript" src="../scripts/CookieDataStore.js"></script><meta name="file" content="f78cb8c6-055c-58ef-c058-8e6d5cf3a4f8" /><xml xmlns:msxsl="urn:schemas-microsoft-com:xslt"><MSHelp:Attr Name="AssetID" Value="T:AlphaForm.AlphaFormTransformer" /><MSHelp:Keyword Index="A" Term="T:AlphaForm.AlphaFormTransformer" /><MSHelp:Keyword Index="A" Term="frlrfAlphaFormAlphaFormTransformerClassTopic" /><MSHelp:Keyword Index="A" Term="frlrfAlphaFormAlphaFormTransformerMembersTopic" /><MSHelp:Keyword Index="K" Term="AlphaFormTransformer class"></MSHelp:Keyword><MSHelp:Keyword Index="K" Term="AlphaForm.AlphaFormTransformer class"></MSHelp:Keyword><MSHelp:Keyword Index="F" Term="AlphaFormTransformer" /><MSHelp:Keyword Index="F" Term="AlphaForm.AlphaFormTransformer" /><MSHelp:Attr Name="TopicType" Value="apiref" /><MSHelp:Attr Name="TopicType" Value="kbSyntax" /><MSHelp:Attr Name="APIType" Value="Managed" /><MSHelp:Attr Name="APILocation" Value="AlphaForm.dll" /><MSHelp:Attr Name="APIName" Value=".AlphaFormTransformer" /><MSHelp:Attr Name="Locale" Value="en-us"></MSHelp:Attr></xml></head><body><script type="text/javascript">var store = new CookieDataStore('docs');registerEventHandler(window, 'load', function() { var ss = new SplitScreen('control', 'main'); selectLanguage(store.get('lang')); });</script><div id="control"><span class="productTitle">AlphaForm Help</span><br /><span class="topicTitle">AlphaFormTransformer Class</span><br /><div id="toolbar"><span id="chickenFeet"><a href="d4648875-d41a-783b-d5f4-638df39ee413.htm">Namespaces</a> ► <a href="43a6d8c0-dedc-c2a8-e94a-65433da6bed3.htm">AlphaForm</a> ► <span class="nolink">AlphaFormTransformer</span></span><span id="languageFilter"><select id="languageSelector" onchange="var names = this.value.split(' '); toggleVisibleLanguage(names[1]); lfc.switchLanguage(names[0]); store.set('lang',this.value); store.save();"><option value="CSharp cs">C#</option><option value="VisualBasic vb">Visual Basic</option><option value="ManagedCPlusPlus cs">Visual C++</option></select></span><script>var sd = getStyleDictionary(); var lfc = new LanguageFilterController();</script></div></div><div id="main"><span style="color: DarkGray"> </span><div class="summary">
            A single instance of AlphaFormTransformer is added to the form
            to be transformed to an alpha channel border window. It hosts all
            controls to be displayed on the window, the image for the layered
            window that displays the image border, and one or more AlphaFormMarkers
            to construct the main form's region. 
            </div><div class="section"><div class="sectionTitle" onclick="toggleSection(this.parentNode)"><img src="../icons/collapse_all.gif"></img> Declaration Syntax</div><div class="sectionContent"><table class="filter"><tr class="tabs" id="syntaxTabs"><td class="tab" x-lang="CSharp" onclick="st.toggleClass('x-lang','CSharp','activeTab','tab'); sb.toggleStyle('x-lang','CSharp','display','block','none');">C#</td><td class="tab" x-lang="VisualBasic" onclick="st.toggleClass('x-lang','VisualBasic','activeTab','tab'); sb.toggleStyle('x-lang','VisualBasic','display','block','none');">Visual Basic</td><td class="tab" x-lang="ManagedCPlusPlus" onclick="st.toggleClass('x-lang','ManagedCPlusPlus','activeTab','tab'); sb.toggleStyle('x-lang','ManagedCPlusPlus','display','block','none');">Visual C++</td></tr></table><div id="syntaxBlocks"><div class="code" x-lang="CSharp"><pre><span class="keyword">public</span> <span class="keyword">class</span> <span class="identifier">AlphaFormTransformer</span> : <a href="http://msdn2.microsoft.com/en-us/kbxtbzd1">Panel</a></pre></div><div class="code" x-lang="VisualBasic"><pre><span class="keyword">Public</span> <span class="keyword">Class</span> <span class="identifier">AlphaFormTransformer</span> _
	<span class="keyword">Inherits</span> <a href="http://msdn2.microsoft.com/en-us/kbxtbzd1">Panel</a></pre></div><div class="code" x-lang="ManagedCPlusPlus"><pre><span class="keyword">public</span> <span class="keyword">ref class</span> <span class="identifier">AlphaFormTransformer</span> : <span class="keyword">public</span> <a href="http://msdn2.microsoft.com/en-us/kbxtbzd1">Panel</a></pre></div></div><script type="text/javascript">
						var st = new ElementCollection('syntaxTabs');
						var sb = new ElementCollection('syntaxBlocks');
						lfc.registerTabbedArea(st, sb);
						st.toggleClass('x-lang','CSharp','activeTab','tab');
						sb.toggleStyle('x-lang','CSharp','display','block','none');
					</script></div></div><div class="section"><div class="sectionTitle" onclick="toggleSection(this.parentNode)"><img src="../icons/collapse_all.gif"></img> Members</div><div class="sectionContent"><table class="filter"><tr class="tabs" id="memberTabs"><td class="tab" value="all" onclick="mt.toggleClass('value','all','activeTab','tab'); mf.subgroup='all'; ms.process(getInstanceDelegate(mf,'filterElement'));">All Members</td><td class="tab" value="constructor" onclick="mt.toggleClass('value','constructor','activeTab','tab'); mf.subgroup='constructor'; ms.process(getInstanceDelegate(mf,'filterElement'));">Constructors</td><td class="tab" value="method" onclick="mt.toggleClass('value','method','activeTab','tab'); mf.subgroup='method'; ms.process(getInstanceDelegate(mf,'filterElement'));">Methods</td><td class="tab" value="property" onclick="mt.toggleClass('value','property','activeTab','tab'); mf.subgroup='property'; ms.process(getInstanceDelegate(mf,'filterElement'));">Properties</td></tr><tr><td class="line" colspan="2"><label for="public"><input id="public" type="checkbox" checked="true" onclick="mf['public'] = this.checked; ms.process(getInstanceDelegate(mf,'filterElement'));" />Public</label><br /><label for="protected"><input id="protected" type="checkbox" checked="true" onclick="mf['protected'] = this.checked; ms.process(getInstanceDelegate(mf,'filterElement'));" />Protected</label></td><td class="line" colspan="2"><label for="instance"><input id="instance" type="checkbox" checked="true" onclick="mf['instance'] = this.checked; ms.process(getInstanceDelegate(mf,'filterElement'));" />Instance</label><br /><label for="static"><input id="static" type="checkbox" checked="true" onclick="mf['static'] = this.checked; ms.process(getInstanceDelegate(mf,'filterElement'));" />Static</label></td><td class="line" colspan="2"><label for="declared"><input id="declared" type="checkbox" checked="true" onclick="mf['declared'] = this.checked; ms.process(getInstanceDelegate(mf,'filterElement'));" />Declared</label><br /><label for="inherited"><input id="inherited" type="checkbox" checked="true" onclick="mf['inherited'] = this.checked; ms.process(getInstanceDelegate(mf,'filterElement'));" />Inherited</label></td></tr></table><table class="members" id="memberList"><tr><th class="iconColumn">Icon</th><th class="nameColumn">Member</th><th class="descriptionColumn">Description</th></tr><tr data="constructor; public; instance; declared"><td><img src="../icons/pubmethod.gif"></img></td><td><a href="0894bd13-b647-edea-c94a-4a86ae2c95df.htm"><span class="cs">AlphaFormTransformer</span><span class="cpp">AlphaFormTransformer</span><span class="vb">New</span><span class="cs">()</span><span class="cpp">()</span></a></td><td><div class="summary">
            Constructor
            </div><br /></td></tr><tr data="property; public; instance; declared"><td><img src="../icons/pubproperty.gif"></img></td><td><a href="efd6d2f9-5fd7-5f85-084a-63d99fd7f439.htm">CanDrag</a></td><td><div class="summary">
            True if mouse drag on this control drags the entire form (meaning the frame window and main
            form together). This will typically be used when a background image is set to the main form and
            the user wants controls on top of the bitmap. In this case being able to drag by clicking on the 
            background is an assumption most users will make.
            </div><br /></td></tr><tr data="property; public; instance; declared"><td><img src="../icons/pubproperty.gif"></img></td><td><a href="ff7f34ce-9379-bd69-c921-0ac23ea24016.htm">DragSleep</a></td><td><div class="summary">
            When moving the form, this control tries to help the desktop and underlying Windows catch up to
            redrawing invalidated areas (we're actually moving two Windows although the layered
            Window of the pair is double buffered). If it detects we're dragging the Form, it sleeps the main
            thread according to this property. A reasonable value like 30 milliseconds makes for less
            distracting redrawing of the invalidated parts of the desktop. Under Vista this property is
            ignored as the DWM double buffers everything. 
            </div><br /></td></tr><tr data="method; public; instance; declared"><td><img src="../icons/pubmethod.gif"></img></td><td><a href="66dabb61-7384-0edb-d5fd-f6723d2c45e3.htm">Fade(FadeType, Boolean, Boolean, Int32)</a></td><td><div class="summary">
            Fades the composite form (i.e., the frame window and the main form) 
            in or out
            </div><br /></td></tr><tr data="method; protected; instance; declared"><td><img src="../icons/protmethod.gif"></img></td><td><a href="102b3a5d-c988-6da9-cb6a-3ba6c61a987f.htm">OnPaint(PaintEventArgs)</a></td><td><div class="summary">
            Overriden for internal use.
            </div> (Overrides <a href="http://msdn2.microsoft.com/en-us/36cd312w">Control</a>.<a href="http://msdn2.microsoft.com/en-us/21z9fct2">OnPaint(PaintEventArgs)</a>.)<br /></td></tr><tr data="property; public; instance; declared"><td><img src="../icons/pubproperty.gif"></img></td><td><a href="73475978-bdd2-408f-4b2e-df2123b0ccc9.htm">PowerToysFix</a></td><td><div class="summary">
            Microsoft's "PowerToys" Alt+Tab extension which replaces the default  
            Alt+Tab functionality has issues with some video cards and alpha composited
            windows and also with any window that has an owner. When
            the user press Alt+Tab, it shows snapshots for owned windows which
            it should not (a design flaw really), and in our case that
            includes our composited frame window which hosts the bitmap. Second in our
            labs on machines with ATI video cards, it does not
            capture the composited window contents correctly, and somehow corrupts the
            buffered contents. So if the user Alt+Tabs to the frame window, it
            will all of a sudden turn to a semi-transparent white box. As a
            work-around to the corruption you can set PowerToysFix to true 
            at the cost of unnecessarily refreshing the frame window contents (normally double
            buffered by the OS) when this control gets a paint message.
            </div><br /></td></tr><tr data="method; public; instance; declared"><td><img src="../icons/pubmethod.gif"></img></td><td><a href="7b47adf2-c452-9fa1-6702-7de50ebe4086.htm">TransformForm(Byte)</a></td><td><div class="summary">
            This methods does the following:
            <ol><li>Constructs a desktop composited frame window and shows it. This window's
            bitmap is built from this control's <span class="code">BackgroundImage</span>.</li><li>Calls <span class="code">UpdateSkin</span> to updated the frame window's image data
            and build the main form's Region.</li><li>The BackgroundImage is set to the main form's Background image.</li></ol><p>
            This method should only be called *once* from the main form's
            Load event. If the user wants to change the image at runtime,
            <a href="965a03b8-5420-8d60-50ad-c4565a18fa28.htm">UpdateSkin(Bitmap, Bitmap, Byte)</a> should be used.
            </p></div><br /></td></tr><tr data="method; public; instance; declared"><td><img src="../icons/pubmethod.gif"></img></td><td><a href="965a03b8-5420-8d60-50ad-c4565a18fa28.htm">UpdateSkin(Bitmap, Bitmap, Byte)</a></td><td><div class="summary">
            This methods does the following:
            <ol><li>Sets the frame window image data from <span class="parameter">frameBmap</span> and
            scales as needed.</li><li>Constructs the main form's Region from the AlphaFormMarkers in 
            this control.</li><li>Updates the frame window's bitmap.</li><li>Sets the main form's background image to <span class="parameter">backBmap</span> with scaling if 
            needed.</li></ol></div><br /></td></tr></table><script type="text/javascript">
					var mt = new ElementCollection('memberTabs');
					var ms = new ElementCollection('memberList');
					var mf = new MemberFilter();
					mt.toggleClass('value','all','activeTab','tab');
				</script></div></div><div class="section"><div class="sectionTitle" onclick="toggleSection(this.parentNode)"><img src="../icons/collapse_all.gif"></img> Inheritance Hierarchy</div><div class="sectionContent"><table cellspacing="0" cellpadding="0"><tr><td colspan="7"><a href="http://msdn2.microsoft.com/en-us/e5kfa45b">Object</a></td></tr><tr><td><img src="../icons/LastChild.gif"></img></td><td colspan="6"><a href="http://msdn2.microsoft.com/en-us/w4302s1f">MarshalByRefObject</a></td></tr><tr><td> </td><td><img src="../icons/LastChild.gif"></img></td><td colspan="5"><a href="http://msdn2.microsoft.com/en-us/9wbadbce">Component</a></td></tr><tr><td> </td><td> </td><td><img src="../icons/LastChild.gif"></img></td><td colspan="4"><a href="http://msdn2.microsoft.com/en-us/36cd312w">Control</a></td></tr><tr><td> </td><td> </td><td> </td><td><img src="../icons/LastChild.gif"></img></td><td colspan="3"><a href="http://msdn2.microsoft.com/en-us/7xhk8yhk">ScrollableControl</a></td></tr><tr><td> </td><td> </td><td> </td><td> </td><td><img src="../icons/LastChild.gif"></img></td><td colspan="2"><a href="http://msdn2.microsoft.com/en-us/kbxtbzd1">Panel</a></td></tr><tr><td> </td><td> </td><td> </td><td> </td><td> </td><td><img src="../icons/LastChild.gif"></img></td><td><span class="nolink">AlphaFormTransformer</span></td></tr></table></div></div><p><div id="footer"> <p />Copyright 2007 Jeff Anderson</div>Assembly: AlphaForm (Module: AlphaForm) Version: 1.1.1.0</p></div></body></html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
Jeff Anderson has been a computer graphics software developer for over twenty years.

He is a co-founder of Braid Art Labs and a developer of Braid's GroBoto 3D software. Jeff also dabbles in shareware with an expanded version of the AlphaForm control and other programs here.

Comments and Discussions