Winform fade-in and fade-out form and form top

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.