<?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; C#.NET</title>
	<atom:link href="http://www.dottostring.com/tag/cnet/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>
		<item>
		<title>How to use Log4net in ASP.NET Application</title>
		<link>http://www.dottostring.com/2008/11/5-how-to-use-log4net-logging-aspnet-application/</link>
		<comments>http://www.dottostring.com/2008/11/5-how-to-use-log4net-logging-aspnet-application/#comments</comments>
		<pubDate>Sun, 02 Nov 2008 09:44:05 +0000</pubDate>
		<dc:creator>babarjehangir</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[C#.NET]]></category>
		<category><![CDATA[FILE BASED LOGGING]]></category>
		<category><![CDATA[LOG4NET]]></category>
		<category><![CDATA[LOGGING]]></category>

		<guid isPermaLink="false">http://www.dottostring.com/?p=5</guid>
		<description><![CDATA[Logging is an essential part of any application. Following is a simple step by step guide to integrate Log4net in your ASP.NET Web Application.
Create a new website

open Microsoft Visual Studio 2005 or 2008, then select File &#8211; &#62; New &#8211; &#62; Website
Enter your desired application path and name for the website.
Select your preferred language ( [...]]]></description>
			<content:encoded><![CDATA[<p>Logging is an essential part of any application. Following is a simple step by step guide to integrate <a title="Log4net" href="http://logging.apache.org/log4net/index.html" target="_blank">Log4net</a> in your ASP.NET Web Application.</p>
<h3><span style="font-weight: normal;">Create a new website</span></h3>
<ul>
<li>open Microsoft Visual Studio 2005 or 2008, then select File &#8211; &gt; New &#8211; &gt; Website</li>
<li>Enter your desired application path and name for the website.</li>
<li>Select your preferred language ( however, in this example we will use C# )</li>
</ul>
<div id="attachment_6" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-6" title="Figure: New Website " src="http://www.dottostring.com/wp-content/uploads/2008/11/newweb.jpg" alt="An Illustration of Adding a New Website in Microsoft Visual Studio 2005 / 2008" width="500" height="330" /><p class="wp-caption-text">An Illustration of adding a new Website in Microsoft Visual Studio  2008</p></div>
<h3><span style="font-weight: normal;">Include Log4net in your website</span></h3>
<ul>
<li>Download <a title="Log4net" href="http://logging.apache.org/log4net/download.html" target="_blank">Log4net</a>.</li>
<li>extract the downloaded folder and look for &lt;log4net_folder&gt;/bin/net/2.0/Log4net.dll</li>
<li>Right-Click the project name and Add a Reference to Log4net.dll</li>
</ul>
<div id="attachment_8" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-8" title="log4net" src="http://www.dottostring.com/wp-content/uploads/2008/11/log4net.jpg" alt="An Illustration of adding Log4net.dll to your website" width="500" height="371" /><p class="wp-caption-text">An Illustration of adding Log4net.dll to your website</p></div>
<h3><span style="font-weight: normal;">Log4net configuration</span></h3>
<ul>
<li>Add a config file to your project with the name log4net.config</li>
<li>Copy paste the following log4net configuration settings to log4net.config file.</li>
</ul>
<pre name="code" class="xml">
&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;log4net&gt;
	&lt;root&gt;
		&lt;level value="DEBUG" /&gt;
		&lt;appender-ref ref="RollingLogFileAppender"/&gt;
	&lt;/root&gt;
	&lt;appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
		&lt;file value="logsapp.log" /&gt;
		&lt;appendToFile value="true" /&gt;
		&lt;rollingStyle value="Size" /&gt;
		&lt;maxSizeRollBackups value="10" /&gt;
		&lt;maximumFileSize value="100KB" /&gt;
		&lt;staticLogFileName value="true" /&gt;
		&lt;layout type="log4net.Layout.PatternLayout"&gt;
			&lt;conversionPattern value="%d [%t]%-5p %c [%x] - %m%n" /&gt;
		&lt;/layout&gt;
	&lt;/appender&gt;
	&lt;appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender"&gt;
		&lt;file value="logsapp.log" /&gt;
		&lt;appendToFile value="false" /&gt;
		&lt;datePattern value="-dddd" /&gt;
		&lt;rollingStyle value="Date" /&gt;
		&lt;layout type="log4net.Layout.PatternLayout"&gt;
			&lt;conversionPattern value="%d [%t]%-5p %c [%x] - %m%n" /&gt;
		&lt;/layout&gt;
	&lt;/appender&gt;
&lt;/log4net&gt;
</pre>
<ul>
<li>Create a folder <strong>logs </strong>in your project directory</li>
</ul>
<div id="attachment_13" class="wp-caption aligncenter" style="width: 510px"><img class="size-full wp-image-13" title="log4netconfig" src="http://www.dottostring.com/wp-content/uploads/2008/11/log4netconfig.jpg" alt="An Illustration of log4net.config file" width="500" height="412" /><p class="wp-caption-text">An Illustration of log4net.config file</p></div>
<h3><span style="font-weight: normal;">Initializing Log4net</span></h3>
<ul>
<li>Add Global.asax to your project and then add the following function to it.</li>
</ul>
<pre name="code" class="c#">
protected void ConfigureLogging()
{
	string logFile = HttpContext.Current.Request.PhysicalApplicationPath + "log4net.config";
	if (System.IO.File.Exists(logFile))
	{
		log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(logFile));
	}
}
</pre>
<ul>
<li>make a call to this function in Application_Start Event.</li>
</ul>
<pre name="code" class="c#">
void Application_Start(object sender, EventArgs e)
{
	// Code that runs on application startup
	ConfigureLogging();
}
</pre>
<h3><span style="font-weight: normal;">Logging Errors and Debugging Information</span></h3>
<ul>
<li>now we are ready to log</li>
<li>declare a log4net.ILog variable in your page which needs to log.</li>
</ul>
<pre name="code" class="c#">
#region Logger Setup
	protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion</pre>
<ul>
<li>Following code in Page_Load demonstrates how to log Debug Information and Errors.</li>
</ul>
<pre name="code" class="c#">
#region Logger Setup
	protected static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
#endregion
protected void Page_Load(object sender, EventArgs e)
{
	try
	{
		log.Debug("In Page Load Function");
		log.Debug("Going to generate divide by zero");
		int a = 0;
		int b = 10 / a;
	}
	catch (Exception ex)
	{
		log.Error(ex.Message, ex);
	}
}
</pre>
<ul>
<li>Run you website and see the results in the logs folder we created earlier. It should contain the file app.log with contents like</li>
</ul>
<pre name="code">
2008-11-02 15:13:09,093 [4]DEBUG _Default [(null)] - In Page Load Function
2008-11-02 15:13:09,140 [4]DEBUG _Default [(null)] - Going to generate divide by zero
2008-11-02 15:13:09,140 [4]ERROR _Default [(null)] - Attempted to divide by zero.
System.DivideByZeroException: Attempted to divide by zero.
at _Default.Page_Load(Object sender, EventArgs e) in d:WorkTestsLoggingSampleDefault.aspx.cs:line 26</pre>
<ul>
<li>thats it, your application is logging properly.</li>
<li>VB.NET developers would need little syntax conversions.</li>
<li>here is the sample code to download: <a href="http://www.dottostring.com/wp-content/uploads/2008/11/loggingsample.zip">Logging Sample</a></li>
</ul>
<script type="text/javascript">
  addthis_url    = 'http%3A%2F%2Fwww.dottostring.com%2F2008%2F11%2F5-how-to-use-log4net-logging-aspnet-application%2F';
  addthis_title  = 'How+to+use+Log4net+in+ASP.NET+Application';
  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/5-how-to-use-log4net-logging-aspnet-application/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
