Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 26th, 2012  |  syntax: None  |  size: 1.83 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C# MDI - how do I prevent the scroll bar?
  2. namespace Controls
  3.  {
  4.   public partial class BaseForm : Form
  5.   {
  6.     public BaseForm()
  7.     {
  8.       InitializeComponent();
  9.       StartPosition = FormStartPosition.WindowsDefaultLocation;
  10.       MaximizeBox = false;
  11.       Width = 806;
  12.       //Width = 850;
  13.       //Height = 760;
  14.       Height = 730;
  15.       //Width = 790;
  16.       //Height = 617;
  17.     }
  18.  
  19.  
  20.     protected override void WndProc(ref Message m)
  21.     {
  22.       const int WM_SYSCOMMAND = 0x0112;
  23.       const int SC_MOVE = 0xF010;
  24.       //ShowScrollBar(this.Handle, (int)ScrollBarDirection.SB_BOTH, false);
  25.       switch (m.Msg)
  26.       {
  27.         case WM_SYSCOMMAND:
  28.           int command = m.WParam.ToInt32() & 0xfff0;
  29.           if (command == SC_MOVE)
  30.             return;
  31.           break;
  32.       }
  33.       base.WndProc(ref m);
  34.     }
  35.   }
  36. }
  37.        
  38. public partial class childform : BaseForm
  39. {
  40.    .......
  41. }
  42.        
  43. internal class MyNativeMDIclient : NativeWindow
  44.     {
  45.         private MdiClient mdiClient;
  46.  
  47.         public MyNativeMDIclient(MdiClient parent)
  48.         {
  49.             mdiClient = parent;
  50.             ReleaseHandle();
  51.             AssignHandle(mdiClient.Handle);            
  52.         }
  53.         internal void OnHandleDestroyed(object sender, EventArgs e)
  54.         {
  55.             ReleaseHandle();
  56.         }
  57.         private const int SB_BOTH = 3;
  58.         [DllImport("user32.dll")]
  59.         private static extern int ShowScrollBar(IntPtr hWnd, int wBar, int bShow);
  60.         protected override void WndProc(ref Message m)
  61.         {
  62.             ShowScrollBar(m.HWnd, SB_BOTH, 0 /*false*/);
  63.             base.WndProc(ref m);
  64.         }
  65.     }
  66.        
  67. foreach (Control control in this.Controls)
  68.             {
  69.                 if (control is MdiClient)
  70.                 {
  71.                     MyNativeMDIclient nw = new MyNativeMDIclient(control);
  72.                     break;
  73.                 }
  74.             }