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

Untitled

By: a guest on May 21st, 2012  |  syntax: None  |  size: 1.70 KB  |  hits: 17  |  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. Moving 2 forms at the same time
  2. protected override void WndProc(ref Message m)
  3.     {
  4.         if (m.Msg == 0x0084)
  5.         {
  6.               Form[] temp = this.OwnedForms;
  7.  
  8.               if(temp.Length > 0)
  9.               {
  10.                     /* moving temp[0] to the same ratio as this form */
  11.               }
  12.  
  13.               m.Result = (IntPtr)2;
  14.               return;
  15.         }
  16.         base.WndProc(ref m);
  17.     }
  18.        
  19. private Point lastPos;
  20.  
  21.     protected override void OnLoad(EventArgs e) {
  22.         base.OnLoad(e);
  23.         lastPos = this.Location;
  24.     }
  25.  
  26.     protected override void OnLocationChanged(EventArgs e) {
  27.         base.OnLocationChanged(e);
  28.         foreach (var frm in this.OwnedForms) {
  29.             frm.Location = new Point(frm.Location.X + this.Left - lastPos.X,
  30.                 frm.Location.Y + this.Top - lastPos.Y);
  31.         }
  32.         lastPos = this.Location;
  33.     }
  34.  
  35.     protected override void WndProc(ref Message m) {
  36.         // Move borderless window with click-and-drag on client window
  37.         if (m.Msg == 0x84) m.Result = (IntPtr)2;
  38.         else base.WndProc(ref m);
  39.     }
  40.        
  41. protected override void WndProc(ref Message m)
  42. {
  43.     Form temp = this.Owner;
  44.  
  45.     if (m.Msg == 0x0084)
  46.     {
  47.           m.Result = (IntPtr)2;
  48.           return;
  49.     }
  50.  
  51.     if (m.Msg == 0x0216 && temp != null)
  52.     {
  53.          if (!movedonce)
  54.          {
  55.               oldlocationx = this.Location.X;
  56.               oldlocationy = this.Location.Y;
  57.               movedonce = true;
  58.          }
  59.  
  60.          temp.Location = new Point(temp.Location.X + this.Location.X - oldlocationx, temp.Location.Y + this.Location.Y - oldlocationy);
  61.          oldlocationx = this.Location.X;
  62.          oldlocationy = this.Location.Y;
  63.     }
  64.  
  65.     base.WndProc(ref m);
  66. }