Click here to Skip to main content
15,879,348 members
Articles / Programming Languages / C#

Window Tabifier

Rate me:
Please Sign up or sign in to vote.
4.91/5 (88 votes)
29 Mar 2008CPOL9 min read 313.5K   9.9K   294  
A simple application for hosting several Windows in one parent window
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace WindowTabifier
{
    public partial class WindowList : Form
    {
        List<window> windows = new List<window>();

        private List<window> selected;

        public List<window> SelectedWindows
        {
            get { return selected; }
            set { selected = value; }
        }

        public WindowList()
        {
            InitializeComponent();
        }
        
        #region EventHandlers

        private void filterBox_TextChanged(object sender, EventArgs e)
        {
            Display(filterBox.Text);
        }

        private void WindowList_Load(object sender, EventArgs e)
        {
            GetWindows();
            Display("");
        }

        private void OKButton_Click(object sender, EventArgs e)
        {
            int count = List.CheckedIndices.Count;

            List<window> copy = windows.FindAll(delegate(window wnd) { return wnd.Title.Contains(filterBox.Text); });
            selected = new List<window>(count);

            for (int i = 0; i < count; i++)
            {
                selected.Add(copy[List.CheckedIndices[i]]);
            }
        }

        private void refreshToolStripButton_Click(object sender, EventArgs e)
        {
            GetWindows();
            Display(filterBox.Text);
        }

        private void CheckAllToolStripButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < List.Items.Count; i++)
            {
                List.SetItemChecked(i, true);
            }
        }

        private void ClearallToolStripButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < List.Items.Count; i++)
            {
                List.SetItemChecked(i, false);
            }
        }

        #endregion

        private void GetWindows()
        {
            if (Properties.Settings.Default.Ignore)
            {
                windows = window.GetOpenWindows().FindAll((window wnd)=>wnd.Title.Length>0 && wnd.GetExecutablePath()!=Application.ExecutablePath);
            }
            else
            {
                windows = window.GetOpenWindows().FindAll((window wnd) => wnd.GetExecutablePath() != Application.ExecutablePath);
            }
        }

        private void Display(string filter)
        {
            List.Items.Clear();

            List<window> copy = windows.FindAll(delegate(window wnd) { return wnd.Title.Contains(filter); });

            foreach (window wnd in copy)
            {
                List.Items.Add(wnd.Title);
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Georgia Georgia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions