Introduction to SDI and MDI in Windows Forms

Source: Internet
Author: User

Windows Forms Medium SDI and MDI IntroductionReleased on: 2008-07-23 | updated on: by Zheng Zuo
Abstract:This article briefly introduces the SDI and MDI application model and implementation in. Net Windows Forms. Content on this pageSummary SDI and mdisingle instancesplash screen concluding remarks OverviewIn the windows application model, a single-instance application and multi-instance application are generally divided. For a single-instance application, multiple-window SDI application and single-instance MDI application are common. SDI And MDIWindows Forms 2.0 programming introduces the application model of Windows Forms in detail. The following lists some features of the two single-instance applications. A. multi-Window SDI applications (Multiple-SDI applications) generally have the following features: only a single instance of the application is run; multiple top-layer windows run independently of each other; the current loaded file will not be re-opened. When the last window is closed, the application will also exit. There is a window menu that allows you to view and select the currently valid top-level window. B. A single-instance MDI Application (single-MDI applications) generally has the following features: only one instance of the application is run; multiple MDI child windows are run in the same MDI parent window; the menu merging function is supported. The sub-window menus are merged to the parent window menu of the MDI according to certain rules. The files already loaded are not re-opened. When the last MDI sub-window is closed, the application does not exit. When the MDI parent form is closed, the application exits. A Window menu allows you to view and select a child window that has been opened. Single InstanceIn. in NET 2.0, FCL provides the windowsformsapplicationbase class to simplify the programming of Windows applications. If you are a developer, you may be surprised that the windowsformsapplicationbase class is not in system. windows. in the forms namespace, it belongs to Microsoft. visualBasic. applicationservices namespace. Maybe this is used as VB. NET developers are preferred. The program set corresponding to this class is Microsoft. VisualBasic. dll, but this assembly is included in the. NET Framework and released. to reference this Assembly, no additional operations are performed on the deployment. The windowsformsapplicationbase class implements some functions similar to the application class. However, this class also contains some interfaces that simplify the development of Windows Forms applications. The following is a brief introduction. The windowsformsapplicationbase class supports a single-instance application. You can simply set the issingleinstance attribute to true and override the onstartupnextinstance method.
Public sealed class singleinstanceapplication: windowsformsapplicationbase {public singleinstanceapplication (): Base () {This. issingleinstance = true; this. shutdownstyle = shutdownmode. aftermainformcloses;} protected override void oncreatemainform () {This. mainform = new mainform ();} protected override void onstartupnextinstance (startupnextinstanceeventargs e) {base. onstartupnextinstance (E); this. mainform. activate ();}}
The singleinstanceapplication class inherits from windowsformsapplicationbase and is set to single-instance mode in the constructor. It is also set to exit the application after the main form is closed. In the inheritance class, the oncreatemainform method is rewritten to create the main form. To ensure that the application runs on a single instance, you also need to override the onstartupnextinstance method. When the next application instance of the application starts, the onstartupnextinstance method is executed. In the preceding implementation code, the main window is activated when the base class method is called. Splash ScreenDuring the initialization of common Windows applications, a startup screen may be used to display the initialization process of the program, such as Microsoft Visual Studio and office software. Windowsformsapplicationbase provides the splashscreen attribute or override the oncreatesplashscreen method to set the startup window. The following shows the implementation code for creating a splashscreen.
Application. splashscreen = new splashscreenform ();
If the splashscreen attribute is empty, the protected showsplashscreen method calls the oncreatesplashscreen method to create an initial screen window.
Protected override void oncreatesplashscreen () {This. splashscreen = new splashscreenform ();}
Maybe we want to implement the singleinstanceapplication class as a single-piece mode, so we can simply adjust the code.
Public sealed class singleinstanceapplication: windowsformsapplicationbase {Private Static readonly singleinstanceapplication application = new singleinstanceapplication (); Private singleinstanceapplication (): Base () {This. issingleinstance = true; this. shutdownstyle = shutdownmode. aftermainformcloses;} public static singleinstanceapplication application {get {return application ;}}}
  ConclusionFor more information about the implementation of multi-window SDI applications and single-instance MDI applications, see Chapter 14, Windows Forms 2.0 programming, the author's website provides sample code for the book and complete content about Chapter 14. This book is written by Chris sells. The second edition contains many. NET 2.0, which provides a detailed description of Windows Forms Application Development. For more information about books, visit the website of Chris sells.

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.