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:
- Create an MDI window form1
Using system. runtime. interopservices; This. ismdicontainer = true;
- 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;
- 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 );
- 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 ;}}}
- 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 ;}}
- 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();}
- 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