1. Fade-in and fade-out forms
Note: There are two implementation methods for fade-in and fade-out forms. The simplest one is to use the form's Opacity attribute (Form transparency), and the other is to use the Win32 function.
2. Pin the form to the top
Note: directly call the Win32 user32.all package and call the setforegroundwindow method.
Source code:
Win32 class:
Imports system. runtime. interopservices </P> <p> public class Win32 <br/> '******************** fade-in and fade-out effect constant * * ********************* <br/> 'Open the window from left to right <br/> Public const aw_hor_positive as int32 = & H1 <br/> 'Open the window from right to left <br/> Public const aw_hor_negative as int32 = & H2 <br/>' Open the window from top to bottom <br/> Public const aw_ver_positive as int32 = & H4 <br/> 'Open the window from bottom to top <br/> Public const aw_ver_negative as int32 = & H8 <br/> 'open the window to the outside <br/> Public const aw_center as int32 = & H10 </P> <p> Public const aw_hide as int32 = & h10000 <br/> 'when the form is uninstalled to use this function, add the constant <br/> Public const aw_activate as int32 = & h20000 <br/>, by default, the focus is lost, unless this constant <br/> Public const aw_slide as int32 = & h40000 </P> <p> Public const aw_blend as int32 = & h80000 <br/> '***** is added '**** **************************************** * *************** </P> <p> 'fade-in and fade-out effect <br/> <dllimport ("user32.dll ", charset: = charset. auto) >_< br/> Public shared function animatewindow (byval hwnd as intptr, byval dwtime as integer, byval dwflags as integer) as Boolean <br/> end function </P> <p> 'sets the form transparency <br/> <dllimport ("user32.dll", entrypoint: = "setlayeredwindowattributes")> _ <br/> Public shared function setlayeredwindowattributes (byval hwnd as long, byval crkey as long, byval balpha as byte, byval dwflags as long) as intptr <br/> end function </P> <p> 'top the window <br/> <dllimport ("user32.dll", entrypoint: = "getforegroundwindow", charset: = charset. auto, exactspelling: = true) >_< br/> Public shared function getforegroundwindow () as intptr <br/> end function </P> <p> <dllimport ("user32.dll", entrypoint: = "setforegroundwindow", charset: = charset. auto, exactspelling: = true) >_< br/> Public shared function setforegroundwindow (byval hwnd as intptr) as intptr <br/> end function <br/> end class <br/>
Call method:
'Double-click to top the window <br/> Public shared sub setbeforeform (byval currentformhandler as intptr) <br/> If currentformhandler <> win32.getforegroundwindow () Then <br/> handler (currentformhandler) <br/> end if <br/> end sub </P> <p> 'fade In and Out Form <br/> Public shared sub formload (byval hwnd as intptr) <br/> win32.animatewindow (hwnd, 2000, win32.aw _ hor_positive) <br/> end sub </P> <p> Public shared sub formclosed (byval hwnd as intptr) <br/> win32.animatewindow (hwnd, 2000, win32.aw _ slide or win32.aw _ hide or win32.aw _ blend) <br/> end sub </P> <p> Public shared sub opacityform (byval newform as system. windows. forms. form) <br/> dim I as double <br/> for I = 0.01 to 1 step 0.01 <br/> newform. opacity = I <br/> system. windows. forms. application. doevents () <br/> system. threading. thread. sleep (5) <br/> next <br/> end sub