Vedremo come creare un form Visual Basic con aero e come fare in modo che venga visualizzata una certa immagine – colore al posto dell’ areo su Windows Xp e precedenti, oppure su 7/Vista con aero disattivato
1 |
<div style="background: #f0f3f3; border-width: .1em .1em .1em .8em; border: solid gray; overflow: auto; padding: .2em .6em; width: auto;"><br /><table><tbody><br /><tr><td><pre style="line-height: 125%; margin: 0;"> 1<br /> 2<br /> 3<br /> 4<br /> 5<br /> 6<br /> 7<br /> 8<br /> 9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48 |
1 |
<span style="color: #006699; font-weight: bold;">Imports</span> <span style="color: #00ccff; font-weight: bold;">System.Runtime.InteropServices</span><br /><span style="color: #006699; font-weight: bold;">Public</span> <span style="color: #006699; font-weight: bold;">Class</span> <span style="color: #00aa88; font-weight: bold;">Form1</span><br /> <span style="color: #0099ff; font-style: italic;">'DPD-APP (r) 2012</span><br /> <span style="color: #006699; font-weight: bold;">Public</span> <span style="color: #006699; font-weight: bold;">Shared</span> <span style="color: #006699; font-weight: bold;">Function</span> <span style="color: #cc00ff;">IsAeroGlassStyleSupported</span>() <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Boolean</span><br /> <span style="color: #006699; font-weight: bold;">Dim</span> isDWMEnable <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Boolean</span> <span style="color: #555555;">=</span> <span style="color: #006699; font-weight: bold;">False</span><br /> <span style="color: #006699; font-weight: bold;">Try</span><br /> <span style="color: #0099ff; font-style: italic;">' Check that the glass is enabled by using the DwmIsCompositionEnabled. </span><br /> <span style="color: #0099ff; font-style: italic;">' It is supported in version 6.0 or above of the operating system.</span><br /> <span style="color: #006699; font-weight: bold;">If</span> Environment.OSVersion.Version.Major <span style="color: #555555;">>=</span> <span style="color: #ff6600;">6</span> <span style="color: #006699; font-weight: bold;">Then</span><br /> <span style="color: #0099ff; font-style: italic;">' Make sure the Glass is enabled by the user.</span><br /> DwmIsCompositionEnabled(isDWMEnable)<br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">If</span><br /> <span style="color: #006699; font-weight: bold;">Catch</span><br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">Try</span><br /><br /> <span style="color: #006699; font-weight: bold;">Return</span> isDWMEnable<br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">Function</span><br /><span style="color: #0099ff; font-style: italic;">'igiguide.blogspot.it</span><br /><span style="color: #330099;"> <StructLayout(LayoutKind.Sequential)></span> _<br /><span style="color: #006699; font-weight: bold;">Public</span> <span style="color: #006699; font-weight: bold;">Structure</span> <span style="color: #00aa88; font-weight: bold;">MARGINS</span><br /> <span style="color: #006699; font-weight: bold;">Public</span> Destra <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Integer</span><br /> <span style="color: #006699; font-weight: bold;">Public</span> Sinistra <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Integer</span><br /> <span style="color: #006699; font-weight: bold;">Public</span> Su <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Integer</span><br /> <span style="color: #006699; font-weight: bold;">Public</span> Giu <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Integer</span><br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">Structure</span><br /> <span style="color: #006699; font-weight: bold;">Declare</span> Auto <span style="color: #006699; font-weight: bold;">Function</span> <span style="color: #cc00ff;">DwmIsCompositionEnabled</span> <span style="color: #006699; font-weight: bold;">Lib</span> <span style="color: #cc3300;">"dwmapi.dll"</span> <span style="color: #006699; font-weight: bold;">Alias</span> <span style="color: #cc3300;">"DwmIsCompositionEnabled"</span> (<span style="color: #006699; font-weight: bold;">ByRef</span> pfEnabled <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Boolean</span>) <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Integer</span><br /> <span style="color: #006699; font-weight: bold;">Declare</span> Auto <span style="color: #006699; font-weight: bold;">Function</span> <span style="color: #cc00ff;">DwmExtendFrameIntoClientArea</span> <span style="color: #006699; font-weight: bold;">Lib</span> <span style="color: #cc3300;">"dwmapi.dll"</span> <span style="color: #006699; font-weight: bold;">Alias</span> <span style="color: #cc3300;">"DwmExtendFrameIntoClientArea"</span> (<span style="color: #006699; font-weight: bold;">ByVal</span> hWnd <span style="color: black; font-weight: bold;">As</span> IntPtr, <span style="color: #006699; font-weight: bold;">ByRef</span> pMargin <span style="color: black; font-weight: bold;">As</span> Margins) <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Integer</span><br /> <span style="color: #006699; font-weight: bold;">Dim</span> pMargins <span style="color: black; font-weight: bold;">As</span> <span style="color: #006699; font-weight: bold;">New</span> MARGINS <span style="color: #006699; font-weight: bold;">With</span> {.Su <span style="color: #555555;">=</span> <span style="color: #555555;">-</span><span style="color: #ff6600;">1</span>, .Sinistra <span style="color: #555555;">=</span> <span style="color: #555555;">-</span><span style="color: #ff6600;">1</span>, .Destra <span style="color: #555555;">=</span> <span style="color: #555555;">-</span><span style="color: #ff6600;">1</span>, .Giu <span style="color: #555555;">=</span> <span style="color: #555555;">-</span><span style="color: #ff6600;">1</span>}<br /> <span style="color: #006699; font-weight: bold;">Private</span> <span style="color: #006699; font-weight: bold;">Sub</span> <span style="color: #cc00ff;">Form1_Load</span>(<span style="color: #006699; font-weight: bold;">ByVal</span> sender <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Object</span>, <span style="color: #006699; font-weight: bold;">ByVal</span> e <span style="color: black; font-weight: bold;">As</span> System.EventArgs) <span style="color: #006699; font-weight: bold;">Handles</span> <span style="color: #006699; font-weight: bold;">Me</span>.Load<br /><br /> <span style="color: #006699; font-weight: bold;">If</span> Form1.IsAeroGlassStyleSupported() <span style="color: #006699; font-weight: bold;">Then</span><br /><br /> <span style="color: #006699; font-weight: bold;">Dim</span> en <span style="color: black; font-weight: bold;">As</span> <span style="color: #007788; font-weight: bold;">Boolean</span> <span style="color: #555555;">=</span> <span style="color: #006699; font-weight: bold;">False</span><br /> DwmIsCompositionEnabled(en)<br /> <span style="color: #006699; font-weight: bold;">If</span> en <span style="color: #006699; font-weight: bold;">Then</span><br /> DwmExtendFrameIntoClientArea(<span style="color: #006699; font-weight: bold;">Me</span>.Handle, pMargins)<br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">If</span><br /> <span style="color: #006699; font-weight: bold;">Me</span>.TransparencyKey <span style="color: #555555;">=</span> Color.FromKnownColor(KnownColor.ActiveCaption)<br /> <span style="color: #006699; font-weight: bold;">Me</span>.BackColor <span style="color: #555555;">=</span> <span style="color: #006699; font-weight: bold;">Me</span>.TransparencyKey<br /> <span style="color: #006699; font-weight: bold;">Me</span>.BackgroundImage <span style="color: #555555;">=</span> <span style="color: #006699; font-weight: bold;">Nothing</span><br /> <br /><span style="color: #0099ff; font-style: italic;">' ELSE facoltativo: aggiungi qui le azioni da fare </span><br /><span style="color: #0099ff; font-style: italic;">'se il computer non ha attivo l' aero</span><br /><br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">If</span><br /><span style="color: #0099ff; font-style: italic;">' DPD- 2013</span><br /> <span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">Sub</span><br /><span style="color: #006699; font-weight: bold;">End</span> <span style="color: #006699; font-weight: bold;">Class</span><br /> |
Semplicemente incollando questo codice e impostando un colore/ un’ immagine come sfondo del form abbiamo fatto tutto il lavoro!
Windows 7 Aero attivo:
Windows 7 senza Aero:
Metro:
Altri Windows: