<?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>Bee Eee Blog &#187; GUI</title>
	<atom:link href="http://blog.bee-eee.com/category/gui/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bee-eee.com</link>
	<description>-- C# hints and tips</description>
	<lastBuildDate>Wed, 23 Dec 2009 19:00:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>c# setting caret position for a richedit control</title>
		<link>http://blog.bee-eee.com/2009/01/06/c-setting-caret-position-for-a-richedit-control/</link>
		<comments>http://blog.bee-eee.com/2009/01/06/c-setting-caret-position-for-a-richedit-control/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 16:47:23 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=67</guid>
		<description><![CDATA[Here&#8217;s the code to set the position of the caret in a richedit control int position = 12; richedit1.Select( position, 0 ); richedit1.ScrollToCaret(); // if you want the position to be shown It&#8217;s that simple.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the code to set the position of the caret in a richedit control</p>
<pre class="code">
int position = 12;
richedit1.Select( position, 0 );
richedit1.ScrollToCaret(); // if you want the position to be shown
</pre>
<p>It&#8217;s that simple.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2009/01/06/c-setting-caret-position-for-a-richedit-control/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>c# force uppercase lettering in a ComboBox</title>
		<link>http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/</link>
		<comments>http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 22:50:36 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/</guid>
		<description><![CDATA[I recently changed from a TextEdit control to a ComboBox and was somewhat annoyed that there wasn&#8217;t a property that forced the input characters to all be uppercase.  So I dug around and came up with the following method using the KeyPress event. private void productNumber_KeyPress(object sender, KeyPressEventArgs e) { char c = e.KeyChar; // [...]]]></description>
			<content:encoded><![CDATA[<p>I recently changed from a TextEdit control to a ComboBox and was somewhat annoyed that there wasn&#8217;t a property that forced the input characters to all be uppercase.  So I dug around and came up with the following method using the KeyPress event.</p>
<pre class="code">
         private void productNumber_KeyPress(object sender, KeyPressEventArgs e)
        {
            char c = e.KeyChar;
            // make it uppercase only
            if (c &gt;= 'a' &amp;&amp; c &lt;= 'z')
            {
                int digit = (int)c;
                digit = digit - 'a' + 'A';
                e.KeyChar = Convert.ToChar(digit);
            }
        }</pre>
<p>When the event handler is called it gives you a chance to edit the hit character.  Just by changing e.KeyChar you change the actual input character.  This is a nifty trick to have under your belt.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/04/28/c-force-uppercase-lettering-in-a-combobox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# getting rid of the jitter!</title>
		<link>http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/</link>
		<comments>http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/#comments</comments>
		<pubDate>Sat, 19 Apr 2008 03:58:03 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/</guid>
		<description><![CDATA[I recently was getting greatly annoyed with some drawing code in my program.  I was drawing a photo that I could zoom and move around.  When I zoomed with the wheel though it would briefly draw the image in two positions.  The first position after it was zoomed, and the second position after it was [...]]]></description>
			<content:encoded><![CDATA[<p>I recently was getting greatly annoyed with some drawing code in my program.  I was drawing a photo that I could zoom and move around.  When I zoomed with the wheel though it would briefly draw the image in two positions.  The first position after it was zoomed, and the second position after it was re-centered on the screen.  Well this looked awful.  Not exactly professional looking.  So I tried a hundered different things.  I tried setting a bool variable in the control to tell the paint function not to draw.  No good.  The drawing was done with asynchronous messages.  Then I tried  BeginInvoke.  That didn&#8217;t work also.  I tried SuspendLayout and ResumeLayout functions of the Control class:  No good.  Finally I just used the Visible property which kind of worked, well I didn&#8217;t get the double picture, but my background was light color and the foreground dark, so there was still a bad looking flicker.  After a couple of hours I finally found the solution at: <a href="http://weblogs.asp.net/jdanforth/archive/2004/03/12/88458.aspx">http://weblogs.asp.net/jdanforth/archive/2004/03/12/88458.aspx</a>.  I worked on the example a little and boiled it down to two functions:  StopDrawing and StartDrawing.</p>
<p>The techinque basically turns of drawing and events to the object on the win32 level underneath .Net.  This is very handy and it worked very very well.  Here is the code.</p>
<pre class="code">
        using System.Runtime.InteropServices;
        private const int WM_SETREDRAW      = 0x000B;
        private const int WM_USER           = 0x400;
        private const int EM_GETEVENTMASK   = (WM_USER + 59);
        private const int EM_SETEVENTMASK   = (WM_USER + 69);

        [DllImport("user32", CharSet = CharSet.Auto)]
        private extern static IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, IntPtr lParam);

        IntPtr eventMask = IntPtr.Zero;

        public void StopDrawing()
        {
            if (drawStopCount == 0)
            {
                // Stop redrawing:
                SendMessage(this.Handle, WM_SETREDRAW, 0, IntPtr.Zero);
                // Stop sending of events:
                eventMask = SendMessage(this.Handle, EM_GETEVENTMASK, 0, IntPtr.Zero);
            }
            drawStopCount++;
        }

        public void StartDrawing()
        {
            drawStopCount--;
            if (drawStopCount == 0)
            {
                // turn on events
                SendMessage(this.Handle, EM_SETEVENTMASK, 0, eventMask);

                // turn on redrawing
                SendMessage(this.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

                Invalidate();
                Refresh();
            }
        }</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/04/18/c-getting-rid-of-the-jitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# drawing outlined text.</title>
		<link>http://blog.bee-eee.com/2008/03/20/c-drawing-outlined-text/</link>
		<comments>http://blog.bee-eee.com/2008/03/20/c-drawing-outlined-text/#comments</comments>
		<pubDate>Thu, 20 Mar 2008 17:14:01 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[graphics]]></category>
		<category><![CDATA[c# graphics gui .Net gdi+]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/03/20/c-drawing-outlined-text/</guid>
		<description><![CDATA[Here is a little nice bit of code to get text to jump out at you no matter what the background.  Outlined text is especially useful when putting text on an image and don&#8217;t have control of the background contrast. Basically it draws a black boarder with a while fill. // prepare to draw text [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a little nice bit of code to get text to jump out at you no matter what the background.  Outlined text is especially useful when putting text on an image and don&#8217;t have control of the background contrast.  Basically it draws a black boarder with a while fill.</p>
<pre class="code">
// prepare to draw text

StringFormat sf = new StringFormat();

sf.Alignment = StringAlignment.Center;

sf.LineAlignment = StringAlignment.Center;// draw the text to a path

System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();

path.AddString(text, Font.FontFamily, 0, 14.0f, fillRect, sf);

// fill in the outline

g.FillPath(Brushes.White, path);

// draw the outline

g.DrawPath(new Pen(Color.Black,2.0f) , path);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/03/20/c-drawing-outlined-text/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>c# writing out a Tiff File using libtiff</title>
		<link>http://blog.bee-eee.com/2008/03/12/c-writing-out-a-tiff-file-using-libtiff/</link>
		<comments>http://blog.bee-eee.com/2008/03/12/c-writing-out-a-tiff-file-using-libtiff/#comments</comments>
		<pubDate>Wed, 12 Mar 2008 15:35:16 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/03/12/c-writing-out-a-tiff-file-using-libtiff/</guid>
		<description><![CDATA[Tiff files are interesting.  They are like the all inclusive file format.  It is an extremely flexible file format that allows for many types of pixel formats that other image formats couldn&#8217;t possibly handle.  For instance 16 bits per channel or sample in the Tiff lingo.  Event the possibility of 4 or 5 samples per [...]]]></description>
			<content:encoded><![CDATA[<p>Tiff files are interesting.  They are like the all inclusive file format.  It is an extremely flexible file format that allows for many types of pixel formats that other image formats couldn&#8217;t possibly handle.  For instance 16 bits per channel or sample in the Tiff lingo.  Event the possibility of 4 or 5 samples per pixel.  If you wanted you could have a Red, Green, Blue, IR, Alpha channel.  Although software would have a difficult time displaying the image.  Anyway I digress &#8212; tiff being somewhat flexible is also some what difficult to manage, this is where libtiff comes in handy.  It handles most of this for us.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0839924992887657";
/* 468x60, created 6/24/08 */
google_ad_slot = "9966844577";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>The first step is to add <span style="color: green">using System.Runtime.InteropServices;</span> to you module.  Then add the stubs for the libtiff functions as follows:</p>
<pre class="code">
    static class TiffHandler
    {
        [DllImport("libtiff3.dll")]
        private static extern int TIFFOpen(String image_path, String opts);
        [DllImport("libtiff3.dll")]
        private static extern void TIFFClose(int handle);
        [DllImport("libtiff3.dll")]
        private static extern void TIFFGetField(int handle, uint property, ref UInt32 value );
        [DllImport("libtiff3.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        private static extern int TIFFSetField(int handle, uint property, uint value);
        [DllImport("libtiff3.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
        private static extern int TIFFSetField(int handle, uint property, string value);
        [DllImport("libtiff3.dll")]
        private unsafe static extern int TIFFReadRGBAImage(int handle, UInt32 width, UInt32 height, byte *raster, int Unkown);
        [DllImport("libtiff3.dll")]
        private unsafe static extern int TIFFReadEncodedStrip(int handle, int strip, byte* buf, int size);
        [DllImport("libtiff3.dll")]
        private unsafe static extern byte* _TIFFmalloc(UInt32 size);
        [DllImport("libtiff3.dll")]
        private unsafe static extern void _TIFFfree(byte* pointer);
        [DllImport("libtiff3.dll")]
        private unsafe static extern void TIFFWriteEncodedStrip(int handle, int offset, byte* buffer, int size);
        [DllImport("libtiff3.dll")]
        private static extern uint TIFFScanlineSize(int handle);
        [DllImport("libtiff3.dll")]
        private static extern int TIFFDefaultStripSize(int handle, int size);
        [DllImport("libtiff3.dll")]
        private unsafe static extern int TIFFWriteScanline(int handle, byte* buffer, int row, int sample);
        [DllImport("libtiff3.dll")]
        private unsafe static extern int TIFFReadScanline(int handle, byte* data, int row, int sample);</pre>
<p>Next we add the constants.  I&#8217;m not going to add them all there are thousands of them but here is an example of the ones that are used in writting a tiff.  If you want more look in the libtiff header files.  It seems like it&#8217;s in tiff.h</p>
<pre class="code">
        const uint TIFFTAG_IMAGEWIDTH = 256;	/* image width in pixels */
        const uint TIFFTAG_IMAGELENGTH	= 257;	/* image height in pixels */
        const uint TIFFTAG_BITSPERSAMPLE = 258;	/* bits per channel (sample) */
        const uint TIFFTAG_SAMPLESPERPIXEL = 277;	/* samples per pixel */
        const uint TIFFTAG_COMPRESSION	= 259;	/* data compression technique */
        const uint COMPRESSION_DEFLATE	= 32946;	/* Deflate compression */
        const uint PHOTOMETRIC_RGB = 2;	/* RGB color model */
        const uint TIFFTAG_PLANARCONFIG = 284;	/* storage organization */
        const uint PLANARCONFIG_CONTIG	= 1;	/* single image plane */</pre>
<p>And then the code to write out the image to a file:</p>
<pre class="code">
        public static unsafe void SaveTiff(string fileName, ImageArray array)
        {
            int tif = TIFFOpen(fileName, "w");
            int Samples = 3;

            TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, (uint)array.Width);
            TIFFSetField(tif, TIFFTAG_IMAGELENGTH, (uint)array.Height);
            TIFFSetField(tif, TIFFTAG_COMPRESSION, COMPRESSION_DEFLATE);
            TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
            TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
            TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, 16);
            TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, (uint)Samples);
            TIFFSetField(tif, TIFFTAG_ARTIST, "Bee Eee Inventions, LLC");

            int cnt = array.Width * array.Height;
            int size = (cnt * Samples * sizeof(ushort));
            ushort* buffer;

            buffer = (ushort*)_TIFFmalloc((uint)size);

            // We set the strip size of the file to be size of one row of pixels
            //int RowSize = TIFFDefaultStripSize(tif, array.Width*3);

            // copy data into buffer
            int i,pos,ptr=0;
            for (i = 0, pos = 0; i &lt; cnt; i++, pos += Samples, ptr++)
            {
                buffer[pos] =  (ushort)(array.Data[ptr].r);
                buffer[pos + 1] = (ushort)(array.Data[ptr].g);
                buffer[pos + 2] = (ushort)(array.Data[ptr].b);
            }

            // Write the information to the file
            TIFFWriteEncodedStrip(tif, 0, (byte *)buffer, size);

            TIFFClose(tif);

            _TIFFfree((byte *)buffer);
        }</pre>
<p>Enjoy.  Next article I&#8217;ll show you how to read some tiff files.  Opening all tiff files could be difficult. :)</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/03/12/c-writing-out-a-tiff-file-using-libtiff/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>c# Measuring a String.</title>
		<link>http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/</link>
		<comments>http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 19:03:13 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[c# .Net GUI]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/</guid>
		<description><![CDATA[Often times it is desirable to draw a string with a System.Drawing.Graphics. My problem came when drawing text over an image. The image itself is dark but had light spots in it. This can make seeing the text very difficult. To fix the problem I fill a box behind the text. To do that I [...]]]></description>
			<content:encoded><![CDATA[<p>Often times it is desirable to draw a string with a <span style="color: green">System.Drawing.Graphics</span>.  My problem came when drawing text over an image.  The image itself is dark but had light spots in it.  This can make seeing the text very difficult.  To fix the problem I fill a box behind the text.  To do that I need to know how tall and wide the text will be.</p>
<p>The magic function is <span style="color: green">Graphics.MeasureString</span>.  This functions returns the calculated size of the string that is being drawn.</p>
<pre class="code">
// measure the string
StringFormat sf = new StringFormat();
sf.Alignment = StringAlignment.Near;
sf.LineAlignment = StringAlignment.Near;
SizeF boundry = g.MeasureString(ToString(), font);

// draw the string
Rectangle textRect = new Rectangle(10, 10, (int)(boundry.Width + 2), (int)(boundry.Height + 2));
g.FillRectangle(Brushes.Black, textRect);
g.DrawRectangle(Pens.White, textRect);
g.DrawString(ToString(), font, Brushes.Yellow, textRect.X, textRect.Y, sf);</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/02/21/c-measuring-a-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>c# Adjusting brightness,contrast, and gamma of an image.</title>
		<link>http://blog.bee-eee.com/2008/01/23/c-adjusting-brightnesscontrast-and-gamma-of-an-image/</link>
		<comments>http://blog.bee-eee.com/2008/01/23/c-adjusting-brightnesscontrast-and-gamma-of-an-image/#comments</comments>
		<pubDate>Wed, 23 Jan 2008 21:02:25 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[graphics]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/2008/01/23/c-adjusting-brightnesscontrast-and-gamma-of-an-image/</guid>
		<description><![CDATA[c# and gdi+ have a simple way to control the colors that are drawn. It&#8217;s basically a ColorMatrix. It&#8217;s a 5&#215;5 matrix that is applied to each color if it is set. Adjusting brightness is just preforming a translate on the color data, and contrast is preforming a scale on the color. Gamma is a [...]]]></description>
			<content:encoded><![CDATA[<p>c# and gdi+ have a simple way to control the colors that are drawn.  It&#8217;s basically a ColorMatrix.  It&#8217;s a 5&#215;5 matrix that is applied to each color if it is set.</p>
<p>Adjusting brightness is just preforming a translate on the color data, and contrast is preforming a scale on the color.  Gamma is a whole different form of transform, but it&#8217;s included in ImageAttributes which accepts the ColorMatrix.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0839924992887657";
/* 468x60, created 6/24/08 */
google_ad_slot = "9966844577";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>So here&#8217;s the simple code:</p>
<pre class="code">
            Bitmap origanalImage;
            Bitmap adjustedImage;
            double brightness = 1.0f; // no change in brightness
            double constrast = 2.0f; // twice the contrast
            double gamma = 1.0f; // no change in gamma

            float adjustedBrightness = brightness - 1.0f;
            // create matrix that will brighten and contrast the image
            float[][] ptsArray ={
                    new float[] {contrast, 0, 0, 0, 0}, // scale red
                    new float[] {0, contrast, 0, 0, 0}, // scale green
                    new float[] {0, 0, contrast, 0, 0}, // scale blue
                    new float[] {0, 0, 0, 1.0f, 0}, // don't scale alpha
                    new float[] {adjustedBrightness, adjustedBrightness, adjustedBrightness, 0, 1}};

            imageAttributes = new ImageAttributes();
            imageAttributes.ClearColorMatrix();
            imageAttributes.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
            imageAttributes.SetGamma(gamma, ColorAdjustType.Bitmap);
            Graphics g = Graphics.FromImage(adjustedImage);
            g.DrawImage(originalImage, new Rectangle(0,0,adjustedImage.Width,adjustedImage.Height)
                ,0,0,bitImage.Width,bitImage.Height,
                GraphicsUnit.Pixel, imageAttributes);</pre>
<p>So there it is.  Simple enough isn&#8217;t it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/01/23/c-adjusting-brightnesscontrast-and-gamma-of-an-image/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>c# .Net double buffering &#8212; plus a little</title>
		<link>http://blog.bee-eee.com/2008/01/08/c-net-double-buffering-plus-a-little/</link>
		<comments>http://blog.bee-eee.com/2008/01/08/c-net-double-buffering-plus-a-little/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 16:25:35 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[c# gui]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=17</guid>
		<description><![CDATA[It seems I left out something that helps the quality of the .Net provided form double buffering when you are doing custom drawing. Just override OnPaintBackground and leaving it blank. This prevents the background from being momentarily drawn when you don&#8217;t want it to be. so again here&#8217;s how to enable double buffering on the [...]]]></description>
			<content:encoded><![CDATA[<p>It seems I left out something that helps the quality of the .Net provided form double buffering when you are doing custom drawing.  Just override OnPaintBackground and leaving it blank.  This prevents the background from being momentarily drawn when you don&#8217;t want it to be.</p>
<p>so again here&#8217;s how to enable double buffering on the form:</p>
<pre class="code">
this.SetStyle(
          ControlStyles.AllPaintingInWmPaint |
          ControlStyles.UserPaint |
          ControlStyles.DoubleBuffer,true);</pre>
<p>And then the override</p>
<pre>
protected override void OnPaintBackground(PaintEventArgs e)
{
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/01/08/c-net-double-buffering-plus-a-little/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Free Asynchronous Message Queue</title>
		<link>http://blog.bee-eee.com/2008/01/07/free-asynchronous-message-queue/</link>
		<comments>http://blog.bee-eee.com/2008/01/07/free-asynchronous-message-queue/#comments</comments>
		<pubDate>Mon, 07 Jan 2008 22:47:12 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[c# coding GUI]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=16</guid>
		<description><![CDATA[If you&#8217;ve ever used a message queue to talk to different parts of your application you know that sometimes you run into a problem with tangled call stacks; especially if one message can causes another message to be sent. However, in c# .Net there is a simple way to untangle the call stack of the [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever used a message queue to talk to different parts of your application you know that sometimes you run into a problem with tangled call stacks; especially if one message can causes another message to be sent.</p>
<p>However, in c# .Net there is a simple way to untangle the call stack of the message queue.  Just use the BeginInvoke method.  This unwinds the stack and uses a delegate to call your message reception handler from the control&#8217;s thread.</p>
<p>For instance:</p>
<pre class="code">
delegate void PostOfficeMessageHandler( POMessage message );

public void SendMessage(Control Sender, POMessage Message)
{
    PostOfficeMessageHandler mh = recipients[Sender];
    Sender.BeginInvoke(mh, Message);
}</pre>
<p>The advantages of this method of deliver are two fold.  1. The stack is unwound.  2.  It makes message handler in the control&#8217;s threads solving some threading issues.</p>
<p>There are a couple of disadvantages.  1. Extra overhead.  2. If the message causes problems you may not know where it&#8217;s coming from!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/01/07/free-asynchronous-message-queue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# capture the mouse &#8212; Get a global hook on the mouse.</title>
		<link>http://blog.bee-eee.com/2008/01/04/c-capture-the-mouse-get-a-global-hook-on-the-mouse/</link>
		<comments>http://blog.bee-eee.com/2008/01/04/c-capture-the-mouse-get-a-global-hook-on-the-mouse/#comments</comments>
		<pubDate>Fri, 04 Jan 2008 21:53:00 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[coding]]></category>

		<guid isPermaLink="false">http://blog.bee-eee.com/?p=13</guid>
		<description><![CDATA[I&#8217;m developing a component that is like the sidebar in the Visual C# Express (c). To get it to appear when the mouse is over the control isn&#8217;t a problem, however I soon discovered that using the MouseEnter and MouseLeave didn&#8217;t work. When I went over child controls the MouseLeave would be called and cause [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m developing a component that is like the sidebar in the Visual C# Express (c).  To get it to appear when the mouse is over the control isn&#8217;t a problem, however I soon discovered that using the MouseEnter and MouseLeave didn&#8217;t work.  When I went over child controls the MouseLeave would be called and cause my sidebar to collapse.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-0839924992887657";
/* 468x60, created 6/24/08 */
google_ad_slot = "9966844577";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script><br />
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<p>Instead I had to create a global mouse hook so that no matter what control the mouse was over I could get a mouse event.</p>
<p>First was the code to import the hook function:</p>
<pre class="code">
// create a mouse over eventstatic int WH_MOUSE_LL = 14;
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
static extern IntPtr GetModuleHandle(string moduleName);

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, uint dwThreadId);

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern int UnhookWindowsHookEx(IntPtr hhook);

[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr CallNextHookEx(IntPtr hhk, int nCode, uint wParam, IntPtr lParam);
delegate IntPtr HookProc(int nCode, uint wParam, IntPtr lParam);

private HookProc hookProc;
private IntPtr hook;</pre>
<p>Here is the event handler</p>
<pre class="code">
IntPtr LowLevelMouseProc(int nCode, uint wParam, IntPtr lParam)
{
    // get the current mouse position
    Point p = Cursor.Position;

    // convert to client rectangle to screen position
    Rectangle r = RectangleToScreen(ClientRectangle);

    // check to see if mouse is within control bounds
    bool exp = (p.Y &gt; r.Top &amp;&amp; p.Y &lt; r.Bottom &amp;&amp; p.X &gt; r.Left &amp;&amp; p.X &lt; r.Right);

    // adjust the expansion
    if (exp != Expanded)
         Expanded = exp;

    // Finished with this
    return CallNextHookEx(IntPtr.Zero, nCode, wParam, lParam);
}</pre>
<p>Then the initialization code I put in the OnLoad event handler:</p>
<pre class="code">
if (!DesignMode)
{
    hookProc = new HookProc(LowLevelMouseProc);
    hook = SetWindowsHookEx(WH_MOUSE_LL, hookProc, GetModuleHandle(null), 0);
}</pre>
<p>And then code for closing in the OnHandleDestroyed event handler:</p>
<pre class="code">
protected override void OnHandleDestroyed(EventArgs e)
{
        UnhookWindowsHookEx(hook);
        base.OnHandleDestroyed(e);
}</pre>
<p>That should just about do it then.  Now the UserControl can sense whether the mouse is overhead whether or not the mouse is over a child control.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.bee-eee.com/2008/01/04/c-capture-the-mouse-get-a-global-hook-on-the-mouse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

