<?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>Coded - Web Development and Programming Blog &#187; User Interface</title>
	<atom:link href="http://www.codedblog.com/category/user-interface/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.codedblog.com</link>
	<description>C#, ASP.NET, Google, Remoting, AJAX, Silverlight, Web Development</description>
	<lastBuildDate>Wed, 16 Jul 2008 13:15:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to auto zoom and auto center Google Maps</title>
		<link>http://www.codedblog.com/2007/09/28/how-to-auto-zoom-and-auto-center-google-maps/</link>
		<comments>http://www.codedblog.com/2007/09/28/how-to-auto-zoom-and-auto-center-google-maps/#comments</comments>
		<pubDate>Fri, 28 Sep 2007 16:03:45 +0000</pubDate>
		<dc:creator>Andrei Alecu</dc:creator>
				<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Programming]]></category>

		<guid isPermaLink="false">http://www.codedblog.com/2007/09/28/how-to-auto-zoom-and-auto-center-google-maps/</guid>
		<description><![CDATA[	This post discusses how to auto center and auto zoom a Google Map to display all of the markers optimally.
	In order to get accomplish this, you have to calculate the center point and zoom level manually via code. Fortunately this is pretty easy to do, you just need to calculate the minimum and maximum latitude/longitude [...]]]></description>
			<content:encoded><![CDATA[	<p>This post discusses how to auto center and auto zoom a <a href="http://www.google.com/apis/maps/">Google Map</a> to display all of the markers optimally.</p>
	<p>In order to get accomplish this, you have to calculate the center point and zoom level manually via code. Fortunately this is pretty easy to do, you just need to calculate the minimum and maximum latitude/longitude of all of your markers and then get the center point of the resulting area (which will be a rectangle).<span id="more-22"></span></p>
	<p>I&#8217;m using the <a href="http://en.googlemaps.subgurim.net/">Google Maps for ASP.NET control by Subgurim</a>, but this method should apply to any other control, and should even work with plain JavaScript.</p>
	<h3>Auto center</h3>
	<p>First, you will need to find out the min/max latitude and longitude for your markers, this can usually be done in one pass at the same time as you add them. Here&#8217;s some Visual Basic.NET code to help you out (I&#8217;m using VB.NET for this project at the request of my collaborator, but it should be easy to convert to C# &#8211; think of it as pseudo code):</p>
	<p><textarea name="code" class="vb">
        Dim minLongitude As Single = Nothing
        Dim maxLongitude As Single = Nothing
        Dim minLatitude As Single = Nothing
        Dim maxLatitude As Single = Nothing
        &#8217;
        &#8217; add markers 
        For i As Integer = 0 To dataSet.Tables(0).Rows.Count &#8211; 1
            Dim glatlng As New GLatLng
            glatlng.lat = dataSet.Tables(0).Rows(i).Item(&#8220;latitude&#8221;)
            glatlng.lng = dataSet.Tables(0).Rows(i).Item(&#8220;longitude&#8221;)
            &#8217;
            &#8217; First time initialization of the variables
            If minLongitude = Nothing Then minLongitude = glatlng.lng
            If maxLongitude = Nothing Then maxLongitude = glatlng.lng
            If minLatitude = Nothing Then minLatitude = glatlng.lat
            If maxLatitude = Nothing Then maxLatitude = glatlng.lat
            &#8217;
            minLongitude = Math.Min(minLongitude, glatlng.lng)
            maxLongitude = Math.Max(maxLongitude, glatlng.lng)
            minLatitude = Math.Min(minLatitude, glatlng.lat)
            maxLatitude = Math.Max(maxLatitude, glatlng.lat)
            &#8217;
            &#8217; Other code here&#8230;
        Next</textarea></p>
	<p>You then just need to calculate the center point of the resulting area. This is as easy as:</p>
	<p><textarea name="code" class="vb">
        centerLatitude = minLatitude + (maxLatitude &#8211; minLatitude) / 2
        centerLongitude = minLongitude + (maxLongitude &#8211; minLongitude) / 2</textarea></p>
	<p>You can now center your map widget to these coordinates.</p>
	<h3>Auto zoom</h3>
	<p>The auto zoom part is where it gets a little tricky. In my application I&#8217;m calculating the distance in miles from the minLatitude, minLongitude coordinate to the maxLatitude, maxLongitude coordinate.</p>
	<p>The formula for calculating the distance in miles between two coordinates is:</p>
	<p><pre><code>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;miles = (3958.75 * Math.Acos(Math.Sin(latitude1 / 57.2958) * Math.Sin(latitude2 / 57.2958) + Math.Cos(latitude1 / 57.2958) * Math.Cos(latitude2 / 57.2958) * Math.Cos(longitude2 / 57.2958 - longitude1 / 57.2958)))
</code></pre></p>
	<p>By calculating how many miles your markers span, you can make an informed guess on which zoom level to use. For instance, if the distance between the furthest two markers is less than 0.2 miles, then you could use the maximum zoom level available&#8212;which is <strong>16</strong> by the way&#8212;; if the distance is more than 0.2 miles and less than 0.5 miles&#8212;use zoom level 15, and so on.</p>
	<p>Here&#8217;s a list of zoom levels for distances up to 15 miles:</p>
	<p><textarea name="code" class="vb">
        Select Case miles
            Case Is < 0.2
                GMap1.GZoom = 16
            Case Is < 0.5
                GMap1.GZoom = 15
            Case Is < 1
                GMap1.GZoom = 14
            Case Is < 2
                GMap1.GZoom = 13
            Case Is < 3
                GMap1.GZoom = 12
            Case Is < 7
                GMap1.GZoom = 11
            Case Is < 15
                GMap1.GZoom = 10
            Case Else
                GMap1.GZoom = 9
        End Select</textarea></p>
	<p>That&#8217;s it, your map should now be able to auto zoom and auto center itself on your markers!</p>
	<p>[tags]Google Maps API, Visual Basic.NET[/tags]</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.codedblog.com/2007/09/28/how-to-auto-zoom-and-auto-center-google-maps/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Owner-drawing a Windows.Forms TextBox</title>
		<link>http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/</link>
		<comments>http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/#comments</comments>
		<pubDate>Mon, 17 Sep 2007 12:23:20 +0000</pubDate>
		<dc:creator>Andrei Alecu</dc:creator>
				<category><![CDATA[.NET Framework]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SharpSpell]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/</guid>
		<description><![CDATA[	This article describes how SharpSpell is able to modify existing TextBox controls to display wavy red underlines below misspelled words.
	Here&#8217;s an image to demonstrate what I mean:
	
(This image is borrowed from SharpSpell, but you get the point)
	Overview
	The .NET framework provides means to subclass native Win32 windows and controls by inheriting from the NativeWindow class. 
	This [...]]]></description>
			<content:encoded><![CDATA[	<p>This article describes how <a href="http://www.tachyon-labs.com/sharpspell.aspx">SharpSpell</a> is able to modify existing TextBox controls to display wavy red underlines below misspelled words.</p>
	<p>Here&#8217;s an image to demonstrate what I mean:</p>
	<p><img src="http://www.tachyon-labs.com/Portals/0/winspellasyoutype.png" alt="SharpSpell - ASP.NET spell checker"/><br />
(This image is borrowed from <a href="http://www.tachyon-labs.com/sharpspell.aspx">SharpSpell</a>, but you get the point)<span id="more-17"></span></p>
	<h3>Overview</h3>
	<p>The .NET framework provides means to subclass native Win32 windows and controls by inheriting from the <a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.nativewindow.aspx">NativeWindow</a> class. </p>
	<p>This is exactly what we need to do, and here is the basic outline of our inherited class:</p>
	<p><textarea name="code" class="csharp">
 using System;
 using System.Collections.Generic;
 using System.Text;
 using System.Windows.Forms;
 using System.Drawing;
 namespace CodedBlog
 {
    public class CustomPaintTextBox : NativeWindow
    {
        private TextBox parentTextBox;
        private Bitmap bitmap;
        private Graphics textBoxGraphics;
        private Graphics bufferGraphics;
        // this is where we intercept the Paint event for the TextBox at the OS level
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case 15: // this is the WM_PAINT message
                    // invalidate the TextBox so that it gets refreshed properly
                    parentTextBox.Invalidate();
                    // call the default win32 Paint method for the TextBox first
                    base.WndProc(ref m);
                    // now use our code to draw extra stuff over the TextBox
                    this.CustomPaint();
                    break;
                default:
                    base.WndProc(ref m);
                    break;
            }
        }
        public CustomPaintTextBox(TextBox textBox)
        {
            this.parentTextBox = textBox;
            this.bitmap = new Bitmap(textBox.Width, textBox.Height);
            this.bufferGraphics = Graphics.FromImage(this.bitmap);
            this.bufferGraphics.Clip = new Region(textBox.ClientRectangle);
            this.textBoxGraphics = Graphics.FromHwnd(textBox.Handle);
            // Start receiving messages (make sure you call ReleaseHandle on Dispose):
            this.AssignHandle(textBox.Handle);
        }
        private void CustomPaint()
        {
            // code goes here, see below
        }
    }
 }</textarea></p>
	<p>Now we need to write the custom paint routine. In order to draw underlines underneath words, we need to know where these words are in the first place. We can get these values using Win32 API functions.</p>
	<p>I will not go into detail with these API functions because the code is pretty long and doesn&#8217;t make the object of this article. You can download the support class here: <a href='http://www.codedblog.com/wp-content/uploads/2007/09/nativemethods.zip' title='SharpSpell Native Win32 Methods for measuring text inside a TextBox'>Native Win32 Methods for measuring text inside a TextBox (nativemethods.zip)</a></p>
	<h3>The custom paint method</h3>
	<p>This is the <strong>CustomPaint()</strong> method: </p>
	<p><textarea name="code" class="csharp">
 private void CustomPaint()
 {
     // get the index of the first visible line in the TextBox
     int curPos = TextBoxAPIHelper.GetFirstVisibleLine(textBox);
     curPos = TextBoxAPIHelper.GetLineIndex(textBox, curPos);
     // clear the graphics buffer
     bufferGraphics.Clear(Color.Transparent);
     // * Here&#8217;s where the magic happens
     // For simplicity we&#8217;ll just draw a line underneath a character range.
     // This will be from character 1 to character 5 in this sample.
     // You can of course modify this to underline specific words.
     Point start = TextBoxAPIHelper.PosFromChar(textBox, 1);
     Point end = TextBoxAPIHelper.PosFromChar(textBox, 5);
     // The position above now points to the top left corner of the character.
     // We need to account for the character height so the underlines go
     // to the right place.
     end.X += 1;
     start.Y += TextBoxAPIHelper.GetBaselineOffsetAtCharIndex(textBox, 1);
     end.Y += TextBoxAPIHelper.GetBaselineOffsetAtCharIndex(textBox, 5);
     // Draw the wavy underline.
     DrawWave(start, end);
     // Now we just draw our internal buffer on top of the TextBox.
     // Everything should be at the right place.
     textBoxGraphics.DrawImageUnscaled(bitmap, 0, 0);
 }</textarea></p>
	<p>We use the <strong>DrawWave()</strong> method to draw a wavy line (zig-zag) from one point to another &#8211; you can customize it to your needs:</p>
	<p><textarea name="code" class="csharp">
 private void DrawWave(Point start, Point end)
 {
     Pen pen = Pens.Red;
     if ((end.X &#8211; start.X) > 4)
     {
         ArrayList pl = new ArrayList();
         for (int i = start.X; i <= (end.X &#8211; 2); i += 4)
         {
             pl.Add(new Point(i, start.Y));
             pl.Add(new Point(i + 2, start.Y + 2));
         }
         Point [] p = (Point[])pl.ToArray(typeof(Point));
         bufferGraphics.DrawLines(pen, p);
     }
     else 
     {
         bufferGraphics.DrawLine(pen, start, end);
     }
 }</textarea></p>
	<p>Now to use this class, you just need to instantiate it by passing a TextBox control to the constructor. Make sure you keep a reference to it at the module level so it doesn&#8217;t get eaten by the Garbage Collector.</p>
	<p><code>CustomPaintTextBox customUnderlines = new CustomPaintTextBox(textBox1);</code></p>
	<p>I haven&#8217;t really tested this stripped out version of the class, but it should work. Most of it is taken directly from the <a href="http://www.tachyon-labs.com/sharpspell.aspx">SharpSpell</a> source code.</p>
	<p>I hope this article helps you understand how to owner draw native Win32 controls using the .NET framework. If you have any questions please leave a comment.</p>
	<p>[tags]Windows.Forms, C#, User Interface, .NET Framework, Win32[/tags]</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.codedblog.com/2007/09/17/owner-drawing-a-windowsforms-textbox/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Google Web Toolkit and ASP.NET?</title>
		<link>http://www.codedblog.com/2007/08/29/google-web-toolkit-and-c/</link>
		<comments>http://www.codedblog.com/2007/08/29/google-web-toolkit-and-c/#comments</comments>
		<pubDate>Thu, 30 Aug 2007 03:42:29 +0000</pubDate>
		<dc:creator>Andrei Alecu</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://www.codedblog.com/2007/08/29/google-web-toolkit-and-c/</guid>
		<description><![CDATA[	Now that Google&#8217;s Web Toolkit is out of beta, I&#8217;m looking at ways of integrating it somehow with C# and ASP.NET.
	First of all, if you don&#8217;t know what Google Web Toolkit is, here&#8217;s a quickie: it is a framework for creating Web 2.0 AJAX Web Applications using the Java language, preferably inside an Integrated Development [...]]]></description>
			<content:encoded><![CDATA[	<p>Now that <a href="http://code.google.com/webtoolkit/">Google&#8217;s Web Toolkit</a> is <a href="http://google-code-updates.blogspot.com/2007/08/google-web-toolkit-out-of-beta-as-of-14.html">out of beta</a>, I&#8217;m looking at ways of integrating it somehow with C# and ASP.NET.</p>
	<p>First of all, if you don&#8217;t know what <strong>Google Web Toolkit</strong> is, here&#8217;s a quickie: it is a framework for creating Web 2.0 AJAX Web Applications using the Java language, preferably inside an Integrated Development Environment (IDE) such as <a href="http://www.eclipse.org/">Eclipse.</a> You then compile this from Java to HTML/JavaScript using the provided tools, and you have a <em>desktop application</em>-like web-page without knowing anything about the W3C DOM, HTML or JavaScript.</p>
	<h3>What does this have to do with C#?</h3>
	<p>Well, don&#8217;t get me wrong, the <a href="http://ajax.asp.net">ASP.NET AJAX Toolkit</a> is amazing, but being able to visually design a page and use JavaScript behaviors and AJAX from inside an IDE is a step forward.</p>
	<p>It seems that <a href="http://www.nikhilk.net/" title="Nikhil Kothari's Blog">Nikhil Kothari</a> from Microsoft is working on a <strong>C# to JavaScript compiler</strong>, called <a href="http://www.nikhilk.net/ScriptSharpIntro.aspx">Script#</a>, as a side project of his. Unfortunately, <strong>Script#</strong> is not currently supported by Microsoft, and they are really losing ground on the AJAX field because of this. They should promote this to a corporate project, I would love having that same power that <strong>GWT</strong> has, but directly in the Visual Studio IDE.<br />
<span id="more-9"></span><br />
Most would argue that <strong>AJAX.NET</strong> is enough, and they are right, it&#8217;s ok for most sites, but for a fully interactive Web application that doesn&#8217;t have to postback to the server for every single user interaction &#8211; it isn&#8217;t. Not if you don&#8217;t want to mess with JavaScript anyway.</p>
	<p><strong>Script#</strong> helps in this regard, but <strong>GWT</strong> is much more powerful, and writing a RPC web-service in C#/ASP.NET that <strong>Google Web Toolkit</strong> can use shouldn&#8217;t be too hard. I&#8217;ll post my findings on this topic in a future post.</p>
	<p>Stay tuned!</p>
	<p>[tags]Google, Google Web Toolkit, C#, ASP.NET, Script#[/tags]</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.codedblog.com/2007/08/29/google-web-toolkit-and-c/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Green Marinee Wide WordPress Theme</title>
		<link>http://www.codedblog.com/2007/08/28/green-marinee-wide-wordpress-theme/</link>
		<comments>http://www.codedblog.com/2007/08/28/green-marinee-wide-wordpress-theme/#comments</comments>
		<pubDate>Tue, 28 Aug 2007 20:19:07 +0000</pubDate>
		<dc:creator>Andrei Alecu</dc:creator>
				<category><![CDATA[User Interface]]></category>
		<category><![CDATA[Web Design]]></category>

		<guid isPermaLink="false">http://www.codedblog.com/?p=7</guid>
		<description><![CDATA[	While looking around trying to find a theme for this blog I came across the great Green Marinee Theme theme by Ian Main .
	The theme has one flaw:
	While I&#8217;m pretty sure that back in 2005 screen resolutions such as 800&#215;600 were still common, in today&#8217;s world the theme is just too narrow for a big [...]]]></description>
			<content:encoded><![CDATA[	<p>While looking around trying to find a theme for this blog I came across the great <a href="http://e-lusion.com/greenmarinee/">Green Marinee Theme</a> theme by <a href="http://e-lusion.com">Ian Main</a> .</p>
	<h3>The theme has one flaw:</h3>
	<p>While I&#8217;m pretty sure that back in 2005 screen resolutions such as 800&#215;600 were still common, in today&#8217;s world the theme is just too narrow for a big screen display, and too much space is lost.</p>
	<p>This is especially a problem with a blog such as mine because I frequently use code samples, and lines can get pretty long.</p>
	<h3>My update:</h3>
	<p>So, I decided to keep the theme, but I modified it to make it exactly 200 pixels wider. I also added a <strong>Latest Posts</strong> display to the right navigation bar to improve the overall usability, and more importantly: <strong>Widget Support</strong><br />
<span id="more-7"></span></p>
	<h3>Downloading the theme:</h3>
	<p>If you want to use the theme you can download it from here: <a href="http://www.codedblog.com/wp-content/uploads/2007/08/greenmarineewide.zip" title="Green Marinee Wide WordPress Theme">Green Marinee Wide WordPress Theme</a></p>
	<p>[tags]WordPress, WordPress Theme, Green Marinee[/tags]</p>

 ]]></content:encoded>
			<wfw:commentRss>http://www.codedblog.com/2007/08/28/green-marinee-wide-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
