DOTNET desktop program transformation plan. Window. Visual Studio. NET style MDI window

Source: Internet
Author: User
Tags dotnet

Is a normal MDI, window style, not very nice, right.

In fact, it is easy to implement this with just a few lines of code.
The reason is that a friend asked me how to implement it. I just remembered it. I have done it before, but not using. net.
After several experiments, I finally got it done under. net. I would like to share this article with csdn's friends,
Do not scold me for anything wrong in a hurry or not detailed enough..

Implementation Method:

  1. Create an MDI window form1
    Using system. runtime. interopservices;
    This. ismdicontainer = true;

  2. Declare Variables
    Private system. Windows. Forms. mdiclient m_mdiclient;
    Public const int mdis_allchildstyles = 0x0001;
    Public const int gwl_style =-16;
    Public const int gwl_exstyle =-20;

  3. Declare APIs
    [Dllimport ("user32.dll", charset = charset. Auto)]
    Public static extern intptr setwindowlong (intptr hwnd, int nindex, int dwnewlong );
    [Dllimport ("user32.dll", charset = charset. Auto)]
    Public static extern intptr getwindowlong (intptr hwnd, int nindex );

  4. In form1 Constructor
    Public form1 () {// The required // initializecomponent (); this. windowstate = formwindowstate. maximized; int icnt = This. controls. count; For (INT I = 0; I <icnt; I ++) {If (this. controls [I] is system. windows. forms. mdiclient) {This. m_mdiclient = (system. windows. forms. mdiclient) This. controls [I]; int style = getwindowlong (m_mdiclient.handle, gwl_style ). toint32 (); style | = mdis_allchildstyles; // setwindowlong (m_mdiclient.handle, gwl_style, style); // set the MDI Region Extension style // remove the MDI window sag. Based on Windows's years of experience, the extended Style 0 must be a flat setwindowlong (m_mdiclient.handle, gwl_exstyle, 0); m_mdiclient.controladded + = new controleventhandler (m_mdiclient_controladded); break ;}}}

  5. Write m_mdiclient_controladded event
    Private void m_mdiclient_controladded (Object sender, controleventargs e) {form FRM = E. Control as form; If (FRM! = NULL) {// change the style of the added MDI subwindow, and then maximize frm. formborderstyle = formborderstyle. None; frm. windowstate = formwindowstate. maximized ;}}
  6. In the load event of form1
    private void Form1_Load(object sender, System.EventArgs e){Form2 f2 =new Form2();f2.MdiParent=this;f2.Show();f2.Activate();}
  7. Create a form2 instance and put the DataGrid dock on it. Select fill for the attribute and run the program to see the effect.

Repost this article, and repost the address and author.

Qu bin2005-3-13

Related Article

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.