2011-10-22 177 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); 
} 
相关问题