Advertisement
InfinityExistz

C Sharp Dock a Window

Sep 9th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. '
  2. '''Docks a window to side of Desktop.
  3.  
  4. private void Form1_MouseUp(object sender, MouseEventArgs e)
  5.          {
  6.              Screen screen = Screen.FromControl(this);
  7.              if (OnRight(this))
  8.              {
  9.                  Left = (screen.Bounds.Width) - Width;
  10.                  Top = (screen.Bounds.Height / 2) - (Height / 2);
  11.              }
  12.              else if (OnLeft(this))
  13.              {
  14.                  Left = 0;
  15.                  Top = (screen.Bounds.Height / 2) - (Height / 2);
  16.              }
  17.              else if (OnBottom(this))
  18.              {
  19.                  Left = (screen.Bounds.Width / 2) - (Width / 2);
  20.                  Top = (screen.Bounds.Height) - (Height);
  21.              }
  22.              else
  23.              {
  24.                  Left = (screen.Bounds.Width / 2) - (Width / 2);
  25.                  Top = 0;
  26.              }
  27.          }
  28.  
  29.          private bool OnRight(Form1 f)
  30.          {
  31.              Screen screen = Screen.FromControl(f);
  32.              if (Right > (screen.Bounds.Width / 1.5))
  33.              {
  34.                  return true;
  35.              }
  36.              else
  37.                  return false;
  38.          }
  39.  
  40.          private bool OnLeft(Form1 f)
  41.          {
  42.              Screen screen = Screen.FromControl(f);
  43.              if (Left < (screen.Bounds.Width * .33))
  44.                  return true;
  45.              else
  46.                  return false;
  47.          }
  48.  
  49.          private bool OnBottom(Form1 f)
  50.          {
  51.              Screen screen = Screen.FromControl(f);
  52.              if (Bottom > screen.Bounds.Height * .66)
  53.                  return true;
  54.              else
  55.                  return false;
  56.          }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement