如何禁用listview列大小调整?

如何禁用listview列大小调整?,listview,powershell,Listview,Powershell,我想禁用listview列大小调整。我怎么做 Add a new class to your project and paste the code shown below. Build. Drag the new control from the top of your toolbox onto a form. using System; using System.Windows.Forms; using System.Runtime.InteropServices; publi

我想禁用listview列大小调整。我怎么做

Add a new class to your project and paste the code shown below.  Build.  Drag the new control from the top of your toolbox onto a form. 

using System; 
using System.Windows.Forms; 
using System.Runtime.InteropServices; 

public class FixedColumnView : ListView { 
  private HeaderWindow mHeader; 
  public FixedColumnView() { 
    this.View = View.Details; 
  } 
  protected override void WndProc(ref Message m) { 
    Console.WriteLine(m.ToString()); 
    if (m.Msg == WM_DESTROY) { 
      // Un-subclass header control 
      if (mHeader != null) mHeader.ReleaseHandle(); 
      mHeader = null; 
    } 
    if (m.Msg == WM_NOTIFY) { 
      // Prevent dragging 
      NMHDR nm = (NMHDR)m.GetLParam(typeof(NMHDR)); 
      if (nm.code == HDN_BEGINTRACK) { 
        m.Result = (IntPtr)1; 
        return; 
      } 
    } 
    base.WndProc(ref m); 
    if (m.Msg == WM_CREATE) { 
      // Subclass the header control 
      IntPtr hWnd = SendMessage(this.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero); 
      if (mHeader == null || mHeader.Handle != hWnd) { 
        if (mHeader != null) mHeader.ReleaseHandle(); 
        else mHeader = new HeaderWindow(); 
        mHeader.AssignHandle(hWnd); 
      } 
    } 
  } 
  private class HeaderWindow : NativeWindow { 
    protected override void WndProc(ref Message m) { 
      if (m.Msg == WM_SETCURSOR) { 
        // Prevent cursor from changing 
        m.Result = (IntPtr)1; 
        return; 
      } 
      if (m.Msg == WM_LBUTTONDBLCLICK) { 
        // Prevent double-click from changing column 
        return; 
      } 
      base.WndProc(ref m); 
    } 
  } 
  // P/Invoke declarations 
  private const int WM_CREATE = 0x0001; 
  private const int WM_DESTROY = 0x0002; 
  private const int WM_SETCURSOR = 0x0020; 
  private const int WM_NOTIFY = 0x004e; 
  private const int WM_LBUTTONDBLCLICK = 0x0203; 
  private const int LVM_GETHEADER = 0x101f; 
  private const int HDN_FIRST = -300; 
  private const int HDN_BEGINTRACK = HDN_FIRST - 26; 
  [StructLayout(LayoutKind.Sequential)] 
  private struct NMHDR { 
    public int hWndFrom; 
    public int idFrom; 
    public int code; 
  } 
  [DllImport("user32.dll")] 
  private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wp, IntPtr lp);

}
并且也看到了这一点


如果您希望某些列可以调整大小,而另一些列不可以调整大小,请使用。在该控件中,可以为每列指定最大/最小宽度。有关说明,请参阅。

这对我帮助不大。我正在使用powershell。