2011-10-22 178 views
4

我想打開父窗口中最大化windowstate的子窗體。mdi子窗體最大化windowstate - BorderStyle

我不想讓用戶最小化/最大化/關閉該子窗口,

所以我設置爲BorderStyle = None和childwindow還設置MaximizeBoxMinimizeBox屬性False,還設置WindowState = Maximized

但當我運行該程序時,它會顯示該子窗體處於最大化狀態的所有Minimize,RestoreClose按鈕。

,但如果我點擊Restore Down那麼有沒有邊界爲childForm..now沒有辦法把它恢復到最大化狀態也..

我缺少的東西?這是一個錯誤?什麼是使其正確工作的正確方法?

+2

這只是不正確的方式來使用MDI。它只會阻礙你最大限度地保持孩子窗口。使用選項卡式界面或交換UserControls切換視圖。 –

+0

看看在計算器這個鏈接可以幫助你 [如何禁用在C#中的最小化按鈕?] [1] [1]:http://stackoverflow.com/questions/319124/how-禁用最小化按鈕在c – DeveloperX

+0

您嘗試停靠面板? – pushpraj

回答

0

那麼你可以創建自己的表單(custome形式),然後inherite該自定義窗體爲MDI子窗體

你必須把下面的代碼中的「自定義表單」

public partial class BaseForm : Form 
    { 
     public BaseForm() 
     { 
      InitializeComponent(); 
      StartPosition = FormStartPosition.WindowsDefaultLocation; 
      MaximizeBox = false; 
      Width = 806; 
      //Width = 850; 
      //Height = 760; 
      Height = 730; 
      //Width = 790; 
      //Height = 617; 
    } 

//[DllImport("user32.dll")] 
//[return: MarshalAs(UnmanagedType.Bool)] 
//private static extern bool ShowScrollBar(IntPtr hWnd, int wBar, bool bShow); 
//private enum ScrollBarDirection { SB_HORZ = 0, SB_VERT = 1, SB_CTL = 2, SB_BOTH = 3 } 


protected override void WndProc(ref Message m) 
{ 
    const int WM_SYSCOMMAND = 0x0112; 
    const int SC_MOVE = 0xF010; 
    //ShowScrollBar(this.Handle, (int)ScrollBarDirection.SB_BOTH, false); 
    switch (m.Msg) 
    { 
    case WM_SYSCOMMAND: 
     int command = m.WParam.ToInt32() & 0xfff0; 
     if (command == SC_MOVE) 
     return; 
     break; 
    } 
    base.WndProc(ref m); 
} 
} 

你必須而應該把你的MDI子窗體minimum size to '0'size to Width = 806; Height = 730;

我希望它會幫助你...

0

不要將其設置爲格言ISED,只需設置寬度和的MdiParent的高度...

Height = this.Height; 
Width = this.Width; 

this.Width應該是父窗體

希望這會有所幫助,如果它沒有。給我發電子郵件:)

[email protected]

+0

'this.Height'和'this.Width'將設置水平和垂直滾動條,因爲子窗口應小於父窗口,不包括標題欄和邊框。 – dotNETbeginner

-1
Form1 fr = new Form1(); 
fr.MdiParent = this; //set form's parent to Mdiform 
fr.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; //set form without maximize,minimize and close button 
fr.Dock = DockStyle.Fill; //set form's dock property to fill 
fr.Show(); 
0

只是嘗試這一個。

protected override void WndProc(ref Message m) 
{ 
    const int WM_SYSCOMMAND = 0x0112; 
    const int SC_MOVE = 0xf010; 
    switch (m.Msg) 
    { 
     case WM_SYSCOMMAND: 
      int command = m.WParam.ToInt32() & 0xfff0; 
      if (command == SC_MOVE) 
       return; 
      break; 

    } 
    base.WndProc(ref m); 
} 
相關問題