Questions about the C # form auto-hide and load

Source: Internet
Author: User

Recently in a small project to develop a small program with the use of other software, one of the software in the use of work needs to generate reports, there is no other application interface on the display desktop display, it is necessary to automatically hide and load the form, by reading Windows The API enables this to be shared with everyone: The original C # comes with the Hide () and show () method, but the form is defined as a static type when the project is developed, and its corresponding hidden and display form methods cannot be invoked through the This keyword. This is done here through the functions provided by the Windows API, first to get a handle to the currently running form, as follows:

Define a global variable

IntPtr Handle;

[DllImport ("user32.dll", EntryPoint = "FindWindow")]

Private extern static IntPtr FindWindow (string lpclassname, string lpwindowname);

Handle = FindWindow (null, "form name"),//lpwindowname for form name

Next define the constants

Private Const int sw_hide = 0//hidden

Private Const int sw_restore = 9//display

Import Win32 Reference

[DllImport ("User32.dll")]

private static extern bool Showwindowasync (IntPtr hWnd, int ncmdshow);

[DllImport ("User32.dll")]

public static extern int ShowWindow (int hwnd, int ncmdshow);

function can be implemented by calling the method with the global variable handle

Showwindowasync (handle,sw_hide);//Implement Auto-hide

ShowWindow (Handle,sw_restore);//Auto Popup form

Questions about the C # form auto-hide and load

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.