Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads
 
Add your own
alternative version

Window Hiding with C#

, 26 Mar 2012 CPOL
A Window Hider program that demonstrates many C# features
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WindowHider
{
	/// <summary>
	/// Summary description for Chooser.
	/// </summary>
	public class Chooser : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox VisListBox;
		private System.Windows.Forms.Button OkButton;
		private System.Windows.Forms.CheckBox InvisibleBox;
		private System.Windows.Forms.CheckBox NoTitleBox;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Chooser()
		{
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.InvisibleBox = new System.Windows.Forms.CheckBox();
			this.OkButton = new System.Windows.Forms.Button();
			this.VisListBox = new System.Windows.Forms.ListBox();
			this.NoTitleBox = new System.Windows.Forms.CheckBox();
			this.SuspendLayout();
			// 
			// InvisibleBox
			// 
			this.InvisibleBox.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.InvisibleBox.Location = new System.Drawing.Point(8, 185);
			this.InvisibleBox.Name = "InvisibleBox";
			this.InvisibleBox.Size = new System.Drawing.Size(152, 24);
			this.InvisibleBox.TabIndex = 2;
			this.InvisibleBox.Text = "Show invisible windows";
			this.InvisibleBox.CheckedChanged += new System.EventHandler(this.InvisibleBox_CheckedChanged);
			// 
			// OkButton
			// 
			this.OkButton.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			this.OkButton.DialogResult = System.Windows.Forms.DialogResult.OK;
			this.OkButton.Location = new System.Drawing.Point(206, 203);
			this.OkButton.Name = "OkButton";
			this.OkButton.TabIndex = 1;
			this.OkButton.Text = "Accept";
			// 
			// VisListBox
			// 
			this.VisListBox.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
				| System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right);
			this.VisListBox.Location = new System.Drawing.Point(8, 8);
			this.VisListBox.Name = "VisListBox";
			this.VisListBox.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended;
			this.VisListBox.Size = new System.Drawing.Size(274, 173);
			this.VisListBox.TabIndex = 0;
			// 
			// NoTitleBox
			// 
			this.NoTitleBox.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			this.NoTitleBox.Location = new System.Drawing.Point(8, 209);
			this.NoTitleBox.Name = "NoTitleBox";
			this.NoTitleBox.Size = new System.Drawing.Size(160, 24);
			this.NoTitleBox.TabIndex = 3;
			this.NoTitleBox.Text = "Show windows with no title";
			this.NoTitleBox.CheckedChanged += new System.EventHandler(this.NoTitleBox_CheckedChanged);
			// 
			// Chooser
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(290, 234);
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.NoTitleBox,
																		  this.InvisibleBox,
																		  this.OkButton,
																		  this.VisListBox});
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.MinimumSize = new System.Drawing.Size(296, 250);
			this.Name = "Chooser";
			this.Text = "Window Picker";
			this.Load += new System.EventHandler(this.Chooser_Load);
			this.ResumeLayout(false);

		}
		#endregion
		//public property for retrieving selected windows
		public System.Windows.Forms.ListBox.SelectedObjectCollection SelectedWindows
		{
			get
			{
				return(VisListBox.SelectedItems);
			}
		}
		public Window SelectedWindow
		{
			get
			{
				return (Window)VisListBox.SelectedItem;
			}
		}
		//load all available windows
		private void Chooser_Load(object sender, System.EventArgs e)
		{
			VisListBox.Items.Clear();

			VisListBox.BeginUpdate();

			//enumerate thru Windows collection
			Windows wndList = new Windows(InvisibleBox.Checked,NoTitleBox.Checked);
			foreach (Window wnd in wndList) {VisListBox.Items.Add(wnd);}

			VisListBox.EndUpdate();
		}
		private void InvisibleBox_CheckedChanged(object sender, System.EventArgs e)
		{
			this.Chooser_Load(this,EventArgs.Empty);
		}
		private void NoTitleBox_CheckedChanged(object sender, System.EventArgs e)
		{
            this.Chooser_Load(this,EventArgs.Empty);
		}
		public bool MultiSelect
		{
			set
			{
				if (!value)
					VisListBox.SelectionMode = SelectionMode.One;
			}
		}
	}
}

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)

Share

About the Author

Taylor Wood
Web Developer
United States United States
I write c#

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150129.1 | Last Updated 26 Mar 2012
Article Copyright 2002 by Taylor Wood
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid