2011-10-13 18 views
10

Tôi đang phát triển ứng dụng WinForms MDI trong VS2010 (.NET 4.0) và tôi chỉ ghét đường viền 3D trong biểu mẫu mẹ MDI.Làm thế nào để loại bỏ đường viền 3d (chìm) từ thành phần MDIClient trong biểu mẫu MDI cha mẹ?

Vì vậy, bất kỳ ý tưởng nào về cách xóa (làm phẳng hoặc không viền tất cả)?

+1

Không, bạn đang khá mắc kẹt với nó. Lớp MdiClient không có thuộc tính BorderStyle và không có cách rõ ràng nào mà tôi thấy để tạo ra cá thể của nó. –

Trả lời

19

Tôi biết đây là một bài cũ nhưng tôi đã trải qua một thời gian và đau đớn làm việc các công cụ biên giới 3D ra (bởi vì tôi cần nó quá) từ mảnh vỡ trên internet bao gồm:

Elements from Jacob Slusser's page at codeproject.com (Accessed 1st Aug'12)

Vì vậy, ở đây đi:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

namespace MDITest 
{ 
    public static class MDIClientSupport 
    { 
     [DllImport("user32.dll")] 
     private static extern int GetWindowLong(IntPtr hWnd, int nIndex); 

     [DllImport("user32.dll")] 
     private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 

     [DllImport("user32.dll", ExactSpelling = true)] 
     private static extern int SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags); 

     private const int GWL_EXSTYLE = -20; 
     private const int WS_EX_CLIENTEDGE = 0x200; 
     private const uint SWP_NOSIZE = 0x0001; 
     private const uint SWP_NOMOVE = 0x0002; 
     private const uint SWP_NOZORDER = 0x0004; 
     private const uint SWP_NOREDRAW = 0x0008; 
     private const uint SWP_NOACTIVATE = 0x0010; 
     private const uint SWP_FRAMECHANGED = 0x0020; 
     private const uint SWP_SHOWWINDOW = 0x0040; 
     private const uint SWP_HIDEWINDOW = 0x0080; 
     private const uint SWP_NOCOPYBITS = 0x0100; 
     private const uint SWP_NOOWNERZORDER = 0x0200; 
     private const uint SWP_NOSENDCHANGING = 0x0400; 

     public static bool SetBevel(this Form form, bool show) 
     { 
      foreach (Control c in form.Controls) 
      { 
       MdiClient client = c as MdiClient; 
       if (client != null) 
       { 
        int windowLong = GetWindowLong(c.Handle, GWL_EXSTYLE); 

        if (show) 
        { 
         windowLong |= WS_EX_CLIENTEDGE; 
        } 
        else 
        { 
         windowLong &= ~WS_EX_CLIENTEDGE; 
        } 

        SetWindowLong(c.Handle, GWL_EXSTYLE, windowLong); 

        // Update the non-client area. 
        SetWindowPos(client.Handle, IntPtr.Zero, 0, 0, 0, 0, 
         SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | 
         SWP_NOOWNERZORDER | SWP_FRAMECHANGED); 

        return true; 
       } 
      } 
      return false; 
     } 

    } 
} 

Trong hình thức tải gọi sự kiện:

form.SetBevel(false); 

Đừng quên để thay đổi không gian tên và ghi nhớ này là một phương pháp mở rộng nhưng nó có thể được thay đổi để được jsut một lời gọi phương thức trong lớp khác hoặc bạn MDI biểu mẫu gốc.

+0

công việc tuyệt vời man.upvote cho bạn. cảm ơn – Napster

+0

Đó là tuyệt vời .. – Sayka

+0

những gì một anh hùng ..... – zxc

0

Hãy thử thay đổi FormBorderStyle tài sản để FixedSingle

+1

Đây là điều đầu tiên tôi đã thử ... biểu mẫu chính mất "kích hoạt" và biên giới 3D vẫn còn đó! – EmirZ

5

Nếu bạn không muốn nhập thư viện bên ngoài, bạn cũng có thể theo dõi gian lận để định lại kích thước/điều khiển vùng chứa mdi.

protected override void OnLoad(EventArgs e) 
    { 
     var mdiclient = this.Controls.OfType<MdiClient>().Single(); 
     this.SuspendLayout(); 
     mdiclient.SuspendLayout(); 
     var hdiff = mdiclient.Size.Width - mdiclient.ClientSize.Width; 
     var vdiff = mdiclient.Size.Height - mdiclient.ClientSize.Height; 
     var size = new Size(mdiclient.Width + hdiff, mdiclient.Height + vdiff); 
     var location = new Point(mdiclient.Left - (hdiff/2), mdiclient.Top - (vdiff/2)); 
     mdiclient.Dock = DockStyle.None; 
     mdiclient.Size = size; 
     mdiclient.Location = location; 
     mdiclient.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom; 
     mdiclient.ResumeLayout(true); 
     this.ResumeLayout(true); 
     base.OnLoad(e); 
    } 
Các vấn đề liên quan