tags:

views:

22

answers:

1

Hi all,

I want to tile my all open windows Horizontally/Vertically. So that i can see them all together.

Please help me on this ...:-((

+1  A: 

You must have a list of windows before you can tile them. One way to do this is a static property that stores WeakReferences to all window created, like this:

static List<WeakRef> _registeredWindows;

public void RegisterWindow(Window w)
{
  _registeredWindows.Add(new WeakReference(w));
}

Now it is easy to tile all visible registered windows:

public void TileRegisteredWindowsHorizontally()
{
   // Find visible registered windows in horizontal order
   var windows = (
   from weak in _registeredWindows
    let window = weak.Target as Window
    where window!=null && window.Visibility==Visibility.Visible
    orderby window.Left + window.Width/2   // Current horizontal center of window
    select window
  ).ToList();

  // Get screen size
  double screenWidth = SystemParameters.PrimaryScreenWidth;
  double screenHeight = SystemParameters.PrimaryScrenHeight;

  // Update window positions to tile them
  int count = windows.Count();
  foreach(int i in Enumerable.Range(0, count))
  {
    var window = windows[i];
    window.Left = i * screenWidth / count;
    window.Width = screenWidth / count;
    window.Top = 0;
    window.Height = screenHeight;
  }
}

How it works: The first query scans the WeakRefs for visible live windows and sorts them horizontally by their centers. The loop at the ends adjusts the window positions.

Ray Burns