<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.toString() &#187; Windows Form</title>
	<atom:link href="http://www.dottostring.com/tag/windows-form/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dottostring.com</link>
	<description>Programming is our passion</description>
	<lastBuildDate>Sun, 04 Oct 2009 15:57:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to create(make a Windows Form act like) a Docking Window without a container in C#.NET</title>
		<link>http://www.dottostring.com/2008/12/how-to-create-make-a-windows-form-act-like-a-docking-window-without-a-container-in-c-sharp-net/</link>
		<comments>http://www.dottostring.com/2008/12/how-to-create-make-a-windows-form-act-like-a-docking-window-without-a-container-in-c-sharp-net/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 19:29:37 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[Dock In]]></category>
		<category><![CDATA[Dock Out]]></category>
		<category><![CDATA[Docking Window]]></category>
		<category><![CDATA[Move Form]]></category>
		<category><![CDATA[Windows Application]]></category>
		<category><![CDATA[Windows Form]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=145</guid>
		<description><![CDATA[Time to share another interesting requirement I had to deal with when I was working on messaging application some time back(just in case if somebody is interested, I wrote about the Notification bar with smooth message/label scroller), which was how to make a Docking Window without a container.
Since there is no built in feature in [...]]]></description>
			<content:encoded><![CDATA[<p>Time to share another interesting requirement I had to deal with when I was working on messaging application some time back(just in case if somebody is interested, I wrote about the <a href="http://www.dottostring.com/2008/11/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet/" target="_blank">Notification bar with smooth message/label scroller</a>), which was how to make a Docking Window without a container.</p>
<p>Since there is no built in feature in the .NET Framework 2.0 to facilitate this, I decided to yet again  tinkle up with the dynamic positioning of the form on the screen. All I needed was a windows form which could act like Docking Window on the Right of the screen.</p>
<p>I will integrate this piece in the previous application I buit on <a href="http://www.dottostring.com/2008/11/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet/" target="_blank"><em>How to make pop-up / Notification bar with Merssage Ticker (smooth message scroller) over the Task Bar in C#.NET</em></a></p>
<ul>
<li>Create a new Windows application (C#.NET) or Download the application I mentioned above.</li>
<li>Add a new windows form with the name &#8220;DockingWindow&#8221;</li>
<li>Re-Size it such that it looks like a Docking Window ( set <strong>Size </strong>310, 450 ), also set <strong>ControlBox </strong>Property to False and <strong>FormBorderStyle </strong>to None. This will remove the windows normal controls to Close,Minimize and Restore.</li>
<li>Now Add a Panel (ID: pVisiblePart) and set it <strong>Dock</strong> Property to Left.</li>
</ul>
<div id="attachment_148" class="wp-caption aligncenter" style="width: 509px"><img class="size-full wp-image-148" title="An Illustration of Initial Version of Docking Window" src="http://www.dottostring.com/wp-content/uploads/2008/12/initialdockingwindow.jpg" alt="An Illustration of Initial Version of Docking Window" width="499" height="486" /><p class="wp-caption-text">An Illustration of Initial Version of Docking Window</p></div>
<p>Since Docking Window is required to stick to the right side of the desktop and also should resize dynamically such that it matches the height of the working area. Also we would require a Button which will allow us to Dock(&gt;&gt;)/UnDock(&lt;&lt;) the Window.</p>
<h4>Dock (&gt;&gt;)</h4>
<p>This would require us to set the Location of the Docking Window such that only the panel (pVisiblePart) is visible, with the Button Available to UnDock the Window</p>
<h4>Un-Dock(&lt;&lt;)</h4>
<p>This would require us to set the Location back to normal but still sticking to the right side of the screen, with a Button Available to Dock again.</p>
<p>so for the code should look like this.</p>
<pre name="code" class="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace _DotToString_NotificationBarTicker
{
    public partial class DockingWindow : Form
    {
        public DockingWindow()
        {
            InitializeComponent();
            configureThis();
        }
        ///
        /// Gets The Screen Width Available for Work
        ///
        /// Working Width Area
        private int getScreenWidth()
        {
            Rectangle recWorkingArea = new Rectangle();
            recWorkingArea = Screen.PrimaryScreen.WorkingArea;
            return recWorkingArea.Width;
        }
        ///
        /// Gets The Screen Height Available for Work
        ///
        /// Working Height Area
        private int getScreenHeight()
        {
            Rectangle recWorkingArea = new Rectangle();
            recWorkingArea = Screen.PrimaryScreen.WorkingArea;
            return recWorkingArea.Height;
        }
        ///
        /// Initialize the Docking Window Start Location
        ///
        private void configureThis()
        {
            //Dynamically resizing the form to match the height available on the screen
            this.Size = new Size(this.Width, getScreenHeight());
            //Calculating the Horizontal Location of the Form (Docking Window)
            //such that only the panel having the Docking Window's Navigation Control
            //will be visible
            int EndX = getScreenWidth() - pVisiblePart.Width;
            this.Location = new System.Drawing.Point(EndX, 0);
            //Setting the Text of the Button which will act at the Navigation for Docking Window
            this.btnDockUnDock.Text = "&lt;&lt;";
        }
    }
}</pre>
<p>I have documented through the code so that it helps you understand various code statements.</p>
<ul>
<li>Now Run(F5) your project</li>
<li>you should be able to see the following</li>
</ul>
<div id="attachment_157" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/docking-window-screenshot.jpg"><img class="size-medium wp-image-157" title="An Illustration of Initial Docking Window" src="http://www.dottostring.com/wp-content/uploads/2008/12/docking-window-screenshot-300x187.jpg" alt="An Illustration of Initial Docking Window" width="300" height="187" /></a><p class="wp-caption-text">An Illustration of Initial Docking Window</p></div>
<ul>
<li>now we just need to take care of two things,
<ul>
<li>how to Un-Dock the Docking Window?</li>
<li>how to Dock the Docking Window?</li>
</ul>
</li>
</ul>
<h4>How to Un-Dock the Docking Window?</h4>
<p>on the click event of the button we will now change the location of the window such that it gives an effect of coming out from the left.</p>
<pre name="code" class="c#">        private void btnDockUnDock_Click(object sender, EventArgs e)
        {
            if (btnDockUnDock.Text.Trim().Equals("&lt;&lt;"))
                DockOut();
            else
                DockIn();
        }
        ///
        /// Docking Window is brought to the front
        ///
        public void DockOut()
        {
            //Starting Location of the Docking Window
            int StartX = this.Location.X;
            //Calculating the final X Coordinate at which the docking window should
            //settle in order to be completely visible
            int EndX = getScreenWidth() - this.Width;
            //This loops does the trick for us, this will effectively simulate the
            //coming out effect to the docking window, eventually making the window
            //completely visible
            for (int i = StartX; i &gt;= EndX; i--)
            {
                this.Location = new System.Drawing.Point(i, 0);
            }
            //Setting the final location (ensuring the final location)
            this.Location = new System.Drawing.Point(EndX, 0);
            this.btnDockUnDock.Text = "&gt;&gt;";
        }
        ///
        /// Docking Window is Docked Back In
        ///
        public void DockIn()
        {
            //Getting the Start Location for the loop
            int StartX = this.Location.X;
            //Calculation the final x coordinate for the loop to finish
            int EndX = getScreenWidth() - pVisiblePart.Width;
            //This is loop will dock the window back in
            for (int i = StartX; i &lt;= EndX; i++)
            {
                this.Location = new System.Drawing.Point(i, 0);
            }
            this.Location = new System.Drawing.Point(EndX, 0);
            this.btnDockUnDock.Text = "&lt;&lt;";
        }</pre>
<div id="attachment_161" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.dottostring.com/wp-content/uploads/2008/12/docking-window-screenshot-2.jpg"><img class="size-medium wp-image-161" title="An Illustration of Docking Window in Visible Mode: Dock Out" src="http://www.dottostring.com/wp-content/uploads/2008/12/docking-window-screenshot-2-300x187.jpg" alt="An Illustration of Docking Window in Visible Mode: Dock Out" width="300" height="187" /></a><p class="wp-caption-text">An Illustration of Docking Window in Visible Mode: Dock Out</p></div>
<ul>
<li>BINGO!  thats just about it, Docking Window is there to be used.</li>
<li>you can continue adding contents to the form&#8217;s working area just like a common form.</li>
<li>Cheers, don&#8217;t forget to leave in your comments/feedback.</li>
<li>Download the complete source code <a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostringdockingwindow.zip">here</a></li>
</ul>
<p>Related Articles:</p>
<ul>
<li><a href="http://www.dottostring.com/2008/11/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet/" target="_blank">How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET</a></li>
<li><a href="http://www.dottostring.com/2008/12/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-c-sharp-net-how-to-stopstart-the-ticker-on-mouse-hoverleave/" target="_blank">How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET &#8211; How to Stop/Start the Ticker on Mouse Hover/Leave</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Fhow-to-create-make-a-windows-form-act-like-a-docking-window-without-a-container-in-c-sharp-net%2F';
  addthis_title  = 'How+to+create%28make+a+Windows+Form+act+like%29+a+Docking+Window+without+a+container+in+C%23.NET';
  addthis_pub    = 'erfaan';
</script><script type="text/javascript" src="http://s7.addthis.com/js/addthis_widget.php?v=12" ></script>
]]></content:encoded>
			<wfw:commentRss>http://www.dottostring.com/2008/12/how-to-create-make-a-windows-form-act-like-a-docking-window-without-a-container-in-c-sharp-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
