<?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/tag/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>2</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# 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>
	</channel>
</rss>
