<?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 Forms</title>
	<atom:link href="http://www.dottostring.com/category/windows-forms/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 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</title>
		<link>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/</link>
		<comments>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/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 08:29:05 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[ManualResetEvent]]></category>
		<category><![CDATA[Message Smooth Scrolling]]></category>
		<category><![CDATA[Message Ticker]]></category>
		<category><![CDATA[Mouse Hover Leave Events]]></category>
		<category><![CDATA[Notification Bar]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=166</guid>
		<description><![CDATA[With reference to my article How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET , I have been getting inquiries on how to handle certain mouse events. so in this post I will explain how you can make the scroller stop/start on mouse hover/leave events respectively.
before we [...]]]></description>
			<content:encoded><![CDATA[<p>With reference to my article <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> , I have been getting inquiries on how to handle certain mouse events. so in this post I will explain how you can make the scroller stop/start on mouse hover/leave events respectively.</p>
<p>before we go ahead, I feel its important for you as reader to know that this is the third article in the chain.following are reference to the previous articles ( for those who are interested )</p>
<ol>
<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> | <a href="http://www.dottostring.com/wp-content/uploads/2008/11/dottostringnotificationbarticker.zip">Download Source Code</a></li>
<li><a href="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/" target="_blank">How to create (make a Windows Form act like) a Docking Window without a container in C#.NET</a> | <a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostringdockingwindow.zip">Download Source Code</a></li>
</ol>
<p> </p>
<p>moving on.</p>
<p>we have two labels which are working as a smooth vertically scrolling set of messages, this scroll effect is given by a Thread we created with the name <strong>BeginScroll, </strong>so in order to make the labels stop we have to some how make the infinite loop in the BeginScroll thread to stop and vice versa in case of start it again. for that to happen we are going to use a a concept straight out of the operating system textbook i.e. Semaphore/Mutex.</p>
<p>we have to develope a machanism that would allow us to use Signal/Wait strategy. For that .NET Framework has a handy feature called <strong>ManualResetEvent</strong>(<em>details of this is out of the scope of this article, so I would prefer you to look <a href="http://msdn.microsoft.com/en-us/library/system.threading.manualresetevent.aspx" target="_blank">here </a>for further information ) </em></p>
<p>(You can use any of the source code mentioned in the above two articles,I will be using source code from the second article mentioned above in this example)</p>
<ul>
<li>Add the following two global declarations to the code (NotificationTiker.cs)</li>
</ul>
<pre name="code" class="c#">        public ManualResetEvent signalThread = new ManualResetEvent(false);
        private bool keepScrolling;
 </pre>
<ul>
<li>now add the MouseHover and MouseLeave events for the both the labels such that they should match the following code.</li>
</ul>
<pre name="code" class="c#">private void lblMessageOne_MouseHover(object sender, EventArgs e)
        {
            //Set KeepSrcolling variable to false so that the loop
            //in the thread terminates
            keepScrolling = false;
            //Reset Event of the ManualResetEvent will make WaitOne
            //Event in the BeginScroll Thread to block and effectively
            //stopping the scroll effect
            signalThread.Reset();
        }

        private void lblMessageOne_MouseLeave(object sender, EventArgs e)
        {
            //Set Event of the ManualResetEvent will release the blocked
            //Thread (blocked by the WaitOne Method)
            signalThread.Set();
        }

        private void lblMessageTwo_MouseHover(object sender, EventArgs e)
        {
            //Set KeepSrcolling variable to false so that the loop
            //in the thread terminates
            keepScrolling = false;
            //Reset Event of the ManualResetEvent will make WaitOne
            //Event in the BeginScroll Thread to block and effectively
            //stopping the scroll effect
            signalThread.Reset();
        }

        private void lblMessageTwo_MouseLeave(object sender, EventArgs e)
        {
            //Set Event of the ManualResetEvent will release the blocked
            //Thread (blocked by the WaitOne Method)
            signalThread.Set();
        }</pre>
<p>now after making some changes to the scroll function, it should contain the following code</p>
<pre name="code" class="c#">        private void BeginScroll()
        {
            //This variable will take label out of view
            int LabelHeight = -lblMessageOne.Height;
            //This variable will be used to assign out of view variable to bottom of the panel, to re-enter
            int PanelBottom = panel1.Height;
            bool firstEntry = true;
            while (true)
            {
                if (!firstEntry)
                    signalThread.WaitOne();
                keepScrolling = true;
                while (keepScrolling)
                {
                    firstEntry = false;
                    if (lblMessageOne.Location.Y == LabelHeight)
                    {
                        //when label one goes out of view, it is configured to re enter again
                        lblMessageOne.Location = new Point(lblMessageOne.Location.X, PanelBottom);
                    }
                    else
                    {
                        //Scrolling label by decrementing it y-axis location
                        int MessageOneY = lblMessageOne.Location.Y - 1;
                        lblMessageOne.Location = new Point(lblMessageOne.Location.X, MessageOneY);
                    }
                    if (lblMessageTwo.Location.Y == LabelHeight)
                    {
                        //when label one goes out of view, it is configured to re enter again
                        lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, PanelBottom);
                    }
                    else
                    {
                        //Scrolling label by decrementing it y-axis location
                        int MessageTwoY = lblMessageTwo.Location.Y - 1;
                        lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, MessageTwoY);
                    }
                    this.Refresh();
                    Thread.Sleep(50);
                }
            }
        }</pre>
<p> </p>
<ul>
<li>this is it, now Run(F5) the application and test the mouse over and leave events.</li>
<li>Cheers, dont forget to leave comments/feedback.</li>
<li>Download Source Code <a href="http://www.dottostring.com/wp-content/uploads/2008/12/dottostringnotificationbarticker-mouseevents.zip">Here</a>.</li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F12%2Fhow-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%2F';
  addthis_title  = 'How+to+make+pop-up+%2F+Notification+bar+with+Message+Ticker+%28smooth+message+scroller%29+over+the+Task+Bar+in+C%23.NET+%26%238211%3B+How+to+Stop%2FStart+the+Ticker+on+Mouse+Hover%2FLeave';
  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-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/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<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>
		<item>
		<title>How to make pop-up / Notification bar with Message Ticker (smooth message scroller) over the Task Bar in C#.NET</title>
		<link>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/</link>
		<comments>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/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 20:53:10 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#.NET Scroller Ticker Message Labels Smooth]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=97</guid>
		<description><![CDATA[few weeks ago I had to work on an application that had a client piece which was required to act like the a one-way messenger e.g. Supervisors wanted to send in messages to their sub ordinates. one of the requirements was whenever a new message arrived, a notification bar should pop-up over the task bar [...]]]></description>
			<content:encoded><![CDATA[<p>few weeks ago I had to work on an application that had a client piece which was required to act like the a one-way messenger e.g. Supervisors wanted to send in messages to their sub ordinates. one of the requirements was whenever a new message arrived, a notification bar should pop-up over the task bar with all the new messages appearing in a ticker fashion ( also messages should scroll smoothly).</p>
<p>There is no .net control available to achieve this. so I searched the internet in hope to get hold of some (free) third party custom controls, but dint find anything of significant help, all I found was how to make characters within the label text scroll horizontally. so I decided to make something of my own.</p>
<p>problems I had to cope with here were:</p>
<ul>
<li>how to make a windows form act as a pop-up/Notification bar over the task bar?</li>
<li>how to implement message ticker (i.e. smooth scrolling of the messages on the pop-up/Notification bar)?</li>
</ul>
<h5>how to make a windows form act as a pop-up/Notification bar over the task bar?</h5>
<ul>
<li>As always, we begin by creating a new Windows Application (C#.NET)</li>
</ul>
<div id="attachment_99" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-99" title="An illustration of creating a new windows application (C#.NET)" src="http://www.dottostring.com/wp-content/uploads/2008/11/notification-tickernew-project.jpg" alt="An illustration of creating a new windows application (C#.NET)" width="500" height="363" /><p class="wp-caption-text">An illustration of creating a new windows application (C#.NET)</p></div>
<ul>
<li>now by quickly doing the following:
<ul>
<li>Rename the Form1.cs with something meaningful, such as &#8220;NotificationTicker.cs&#8221;, Press &#8220;Yes&#8221; when it asks for renaming reference content.</li>
<li>Re size the form such that it looks like a notification bar.</li>
<li>Drop in a group box from the toolbox and re size it to stretch towards the boundaries.</li>
<li>Drop in a label in the group box area and assign some dummy text to it.</li>
<li>Set ControlBox Property of the Form to false.</li>
<li>Set ShowInTaskbar Property of the Form to false.</li>
</ul>
<p>we get</li>
</ul>
<div id="attachment_106" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-106" title="Notification Ticker Initial Form Sample" src="http://www.dottostring.com/wp-content/uploads/2008/11/notification-tickernotification-tiker-form.jpg" alt="Notification Ticker Initial Form Sample" width="500" height="350" /><p class="wp-caption-text">Notification Ticker Initial Form Sample</p></div>
<ul>
<li>verify that everything is working fine by compiling and running the application (F5)</li>
<li>Width of the form should be equal to the width of the user screen, this is simple, all we need here is to find out the working area of the client machine.</li>
<li>Working Area of the Client Machine is the space on screen available for the Forms to appear (excluding Taskbars, Docked Windows e.t.c).</li>
<li>we get this space in the form of rectangle.</li>
</ul>
<pre name="code" class="c#">Rectangle recWorkingArea = new Rectangle();
recWorkingArea = Screen.PrimaryScreen.WorkingArea;</pre>
<ul>
<li>by using the working area and a bit of mathematics we can get what we want.</li>
</ul>
<pre name="code" class="c#">        private int getScreenWidth()
        {
            Rectangle recWorkingArea = new Rectangle();
            recWorkingArea = Screen.PrimaryScreen.WorkingArea;
            return recWorkingArea.Width;
        }
        private int getScreenHeight()
        {
            Rectangle recWorkingArea = new Rectangle();
            recWorkingArea = Screen.PrimaryScreen.WorkingArea;
            return recWorkingArea.Height;
        }
        private void FitToScreen()
        {
            this.Size = new Size(getScreenWidth(), this.FormHeight);
            this.Location = new System.Drawing.Point(0, this.Location.Y);
        }</pre>
<ul>
<li>FitToScreen() when called will span the form to the width of the user screen.</li>
<li>Now we need to re size the group box as well, that&#8217;s also done with a bit of simple mathematics</li>
</ul>
<pre name="code" class="c#">private void SetGroupBox()
{
    int diff = (this.Location.X + this.Width) - (this.gbNotificationCenter.Location.X + gbNotificationCenter.Width);
    this.gbNotificationCenter.Size = new Size((getScreenWidth() - diff) - this.gbNotificationCenter.Location.X, this.gbNotificationCenter.Height);
}</pre>
<ul>
<li>call these functions ( FitToScreen and SetGroupBox ) in the below sequence in the form constructor and then Run(F5) your application</li>
</ul>
<pre name="code" class="c#">        public NotificationTicker()
        {
            InitializeComponent();
            SetGroupBox();
            FitToScreen();
        }</pre>
<ul>
<li>if you have done everything as right, you should see a form with the same height (as in the design time) but with a width equal to the your screen width.</li>
</ul>
<p>now the pop-up part, this requires a bit of tinkling with the Location.Y ( Top-Left ) of the form. if we can somehow place the form initially at the height of the working area and then start decrementing it till Location.Y(of the form) + Height(of the form) equals Height of the working area, this would do the trick. Also note that all of this code would be written in Activated Event of the form, so that whenever the form is activated this form gives an effect of pop-up notification bar.</p>
<p>define a variable FormHeight and initialize it to a static value of the form height shown at the design time. because of at the runtime Height (of the form) becomes (form height (at design time) + ControlBox height).</p>
<pre name="code" class="c#">private void NotificationTicker_Activated(object sender, EventArgs e)
{
    //firsttime is a global boolean variable initialized to true
    if (firsttime)
    {
        //setting this to false, right away. because activated is called again whenever
        //form gets the focus.
        firsttime = false;
        //Initializing the form to the bottom of the working area ( out of visible area )
        this.Location = new System.Drawing.Point(0, getScreenHeight());
        this.Refresh();
        //Read about the below line in the next section, where we will enable it
        //InitiateScrollingThread();
        //calculating the seed, so that opacity increases from 0% to 100% during the course of popping up.
        double opacityIncreaseSeed = 100.0 / (Convert.ToDouble(this.FormHeight) * 100.0);
        //Starting Index for the loop
        int ScreenHeight = getScreenHeight();
        //End Index for the loop to stop
        int StartY = getScreenHeight() - this.FormHeight;
        for (int i = ScreenHeight; i &gt;= StartY; i--)
        {
            //Increasing opacity gradually
            this.Opacity = this.Opacity + opacityIncreaseSeed;
            //updating the location to give the move up effect
            this.Location = new System.Drawing.Point(0, i);
            this.Refresh();
            //to put some delay.
            Thread.Sleep(10);
        }
        //finally setting Opacity of the form to 100%
        this.Opacity = 1.0;
    }
}</pre>
<ul>
<li>Run(F5) the application and there you have a smooth and graceful pop-up notification bar coming out over the taskbar.</li>
<li><a href="http://www.dottostring.com/wp-content/uploads/2008/11/dottostringnotificationbar.zip">Download</a> Source Code up till here</li>
</ul>
<p>moving on to the second problem</p>
<h5>how to implement message ticker (i.e. smooth scrolling of the messages on the pop-up/Notification bar)?</h5>
<p>This is a bit tricky, but the idea is pretty simple. if you think you can implement smooth scrolling / ticker with two labels potentially. All you need to do is move one label out of the view and simultaneously moving the other one into view, assign a new message to the label that went out of the view and start to move it into the view again while the other one goes out of the view so on and so forth.</p>
<p>to accomplish this we need to drop in a panel and two labels, NOTE: Labels should be placed such that, they are inside the panel.</p>
<div id="attachment_114" class="wp-caption aligncenter" style="width: 510px"><a href="http://www.dottostring.com/wp-content/uploads/2008/11/notification-tickernotification-ticker-with-two-labels1.jpg"><img class="size-full wp-image-114" title="Demonstration of Notification Ticker with Two labels" src="http://www.dottostring.com/wp-content/uploads/2008/11/notification-tickernotification-ticker-with-two-labels1.jpg" alt="Demonstration of Notification Ticker with Two labels" width="500" height="352" /></a><p class="wp-caption-text">Demonstration of Notification Ticker with Two labels</p></div>
<p>here we need to understand that scrolling will be a continuous event and therefore we cannot have this method in the same application thread. we need to create a separate thread to handle the scrolling.</p>
<p>all of this is handled by the following two functions</p>
<pre class="c#" name="code">private void InitiateScrollingThread()
{
    //Bottom of the Panel, will be used for hiding one of the two labels
    int PanelBottom = panel1.Height;
    //Setting the second label below the panel (effectively taking it out of view)
    lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, PanelBottom);
    // we have to set this to false, otherwise we wont able to update the location
    // of the labels from the scrolling thread.
    System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
    //Initializing the scrollerThread(defined globally, Thread scrollerThread)
    scrollerThread = new Thread(BeginScroll);
    //Starting the BeginScroll Function at a separate thread
    scrollerThread.Start();
}
private void BeginScroll()
{
    //This variable will take label out of view
    int LabelHeight = -lblMessageOne.Height;
    //This variable will be used to assign out of view variable to bottom of the panel, to re-enter
    int PanelBottom = panel1.Height;
    while (true)
    {
        if (lblMessageOne.Location.Y == LabelHeight)
        {
            //when label one goes out of view, it is configured to re enter again
            lblMessageOne.Location = new Point(lblMessageOne.Location.X, PanelBottom);
        }
        else
        {
            //Scrolling label by decrementing it y-axis location
            int MessageOneY = lblMessageOne.Location.Y - 1;
            lblMessageOne.Location = new Point(lblMessageOne.Location.X, MessageOneY);
        }
        if (lblMessageTwo.Location.Y == LabelHeight)
        {
            //when label one goes out of view, it is configured to re enter again
            lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, PanelBottom);
        }
        else
        {
            //Scrolling label by decrementing it y-axis location
            int MessageTwoY = lblMessageTwo.Location.Y - 1;
            lblMessageTwo.Location = new Point(lblMessageTwo.Location.X, MessageTwoY);
        }
        this.Refresh();
        Thread.Sleep(50);

    }
}</pre>
<ul>
<li>make a call to InitiateScrollingThread() funcation in the Activated Event defined above (in the if condition after setting the Location of the form)</li>
<li>and that&#8217;s it, we are done.</li>
<li>Run (F5) the application and the see smooth pop-up notification bar over the taskbar and then the smoothly scrolling messages.</li>
<li><a href="http://www.dottostring.com/wp-content/uploads/2008/11/dottostringnotificationbarticker.zip">Download</a> Source Code Here</li>
<li>Cheers (don&#8217;t forget to leave your feedback/concerns)</li>
</ul>
<p>Related Articles:</p>
<ul>
<li><a href="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/" target="_blank">How to create (make a Windows Form act like) a Docking Window without a container 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%2F11%2Fhow-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet%2F';
  addthis_title  = 'How+to+make+pop-up+%2F+Notification+bar+with+Message+Ticker+%28smooth+message+scroller%29+over+the+Task+Bar+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/11/how-to-make-pop-up-notification-bar-with-message-ticker-smooth-message-scroller-over-the-task-bar-in-cnet/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>
