<?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>Simon Ottenhaus &#187; c#</title>
	<atom:link href="http://familie-ottenhaus.de/simon/blog/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://familie-ottenhaus.de/simon/blog</link>
	<description>Uni &#38; Software</description>
	<lastBuildDate>Fri, 23 Dec 2011 13:15:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Listen filtern mit LINQ &#8211; c# Snippets</title>
		<link>http://familie-ottenhaus.de/simon/blog/2011/10/listen-filtern-mit-linq-c-snippets/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2011/10/listen-filtern-mit-linq-c-snippets/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 19:27:15 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=1354</guid>
		<description><![CDATA[Damit die Reihe c# Snippets gleich mit zwei Artikel startet folgt nun noch ein kurzes aber praktisches Snippet. Problemstellung Gegeben ist eine Liste. Gesucht ist eine Teilmenge der Liste, die eine bestimmte Bedingung erfüllt. Beispiel Gegeben: List&#60;int&#62; list = new List&#60;int&#62;() { 5, 3, 17, 2, 23 }; Gesucht ist eine neue Liste, die alle [...]]]></description>
			<content:encoded><![CDATA[<p>Damit die <a href="http://familie-ottenhaus.de/simon/blog/tag/snippets/" class="liinternal">Reihe c# Snippets</a> gleich mit zwei Artikel startet folgt nun noch ein kurzes aber praktisches Snippet.</p>
<p><strong>Problemstellung</strong><br />
Gegeben ist eine Liste.<br />
Gesucht ist eine Teilmenge der Liste, die eine bestimmte Bedingung erfüllt.</p>
<p><strong>Beispiel</strong><br />
Gegeben: <code>List&lt;int&gt; list = new List&lt;int&gt;() { 5, 3, 17, 2, 23 };</code><br />
Gesucht ist eine neue Liste, die alle Elemente größer 10 enthält.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1354code3'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13543"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1354code3"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> list <span style="color: #008000;">=</span> ...<span style="color: #008000;">;</span>
List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> result <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from i <span style="color: #0600FF;">in</span> list where i <span style="color: #008000;">&gt;</span> 10 select i<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>In dem Select-Teil kann auch Code ausgeführt werden, zum Beispiel wenn die Quadrate der Zahlen gesucht sind:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1354code4'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13544"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p1354code4"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> list <span style="color: #008000;">=</span> ...<span style="color: #008000;">;</span>
List<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">int</span><span style="color: #008000;">&gt;</span> result <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>from i <span style="color: #0600FF;">in</span> list where i <span style="color: #008000;">&gt;</span> 10 select i <span style="color: #008000;">*</span> i<span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2011/10/listen-filtern-mit-linq-c-snippets/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2011/10/listen-filtern-mit-linq-c-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SerializeToString &#8211; c# Snippets</title>
		<link>http://familie-ottenhaus.de/simon/blog/2011/10/serializetostring-c-snippets/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2011/10/serializetostring-c-snippets/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 19:10:58 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Snippets]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=1337</guid>
		<description><![CDATA[Dieser Artikel ist der erste Teil der Reihe c# Snippets. Oftmals hat man eine Liste von Elementen möchte diese aber als einen String darstellen. Beispiel Gegegen ist eine Liste von decimal-Werten: List&#60;decimal&#62;list = new list&#60;decimal&#62;{ 1.05, 2.50; 3.66 }; Gewünscht ist "1,05; 2,50; 3,66" Der herkömmliche Ansatz &#8230; sieht dann vermutlich so oder so ähnlich [...]]]></description>
			<content:encoded><![CDATA[<p><em>Dieser Artikel ist der erste Teil der <a href="http://familie-ottenhaus.de/simon/blog/tag/snippets/" class="liinternal">Reihe c# Snippets</a>.</em></p>
<p>Oftmals hat man eine Liste von Elementen möchte diese aber als einen String darstellen.</p>
<p><strong>Beispiel</strong><br />
Gegegen ist eine Liste von decimal-Werten:<br />
<code>List&lt;decimal&gt;list = new list&lt;decimal&gt;{ 1.05, 2.50; 3.66 };</code><br />
Gewünscht ist <code>"1,05; 2,50; 3,66"</code></p>
<p><strong>Der herkömmliche Ansatz</strong><br />
&#8230; sieht dann vermutlich so oder so ähnlich aus:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1337code9'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p13379"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p1337code9"><pre class="csharp" style="font-family:monospace;">StringBuilder sb <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">decimal</span> d <span style="color: #0600FF;">in</span> list<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>d.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.00&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot;;  &quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>sb.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> 0<span style="color: #000000;">&#41;</span> sb.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-=</span><span style="color: #FF0000;">2</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Trennzeichen am Ende entfernen</span>
<span style="color: #0600FF;">return</span> sb.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p><strong>Die Hilfsmethode SerializeToString mit Lamda-Ausdrücken</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1337code10'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p133710"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code" id="p1337code10"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> StringExtensions
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> SerializeToString<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> IEnumerable<span style="color: #008000;">&lt;</span>T<span style="color: #008000;">&gt;</span> list, Func<span style="color: #008000;">&lt;</span>T, <span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> serialize, <span style="color: #FF0000;">string</span> separator<span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
        StringBuilder sb2 <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">Aggregate</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringBuilder<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #000000;">&#40;</span>sb, item<span style="color: #000000;">&#41;</span> <span style="color: #008000;">=&gt;</span> sb.<span style="color: #0000FF;">Append</span><span style="color: #000000;">&#40;</span>serialize<span style="color: #000000;">&#40;</span>item<span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> separator<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>sb2.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&gt;</span> 0<span style="color: #000000;">&#41;</span> sb2.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">-=</span> separator.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
        <span style="color: #0600FF;">return</span> sb2.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p><strong>Der Aufruf von SerializeToString</strong><br />
ist nun wesentlich kürzer und meiner Meinung nach besser lesbar:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1337code11'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p133711"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p1337code11"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">string</span> serializedValues <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">SerializeToString</span><span style="color: #000000;">&#40;</span>d <span style="color: #008000;">=&gt;</span> d.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.00&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p>Natürlich funktioniert dies auch für Listen von komplexeren Datenstrukturen und auch verschachtelt:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1337code12'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p133712"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p1337code12"><pre class="csharp" style="font-family:monospace;">List<span style="color: #008000;">&lt;</span>List<span style="color: #008000;">&lt;</span>DateTime<span style="color: #008000;">&gt;&gt;</span> list <span style="color: #008000;">=</span> ...<span style="color: #008000;">;</span>
&nbsp;
<span style="color: #FF0000;">string</span> serializedValues <span style="color: #008000;">=</span> list.<span style="color: #0000FF;">SerializeToString</span><span style="color: #000000;">&#40;</span>i1 <span style="color: #008000;">=&gt;</span> i1.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; Elemente: &quot;</span> <span style="color: #008000;">+</span> i1.<span style="color: #0000FF;">SerializeToString</span><span style="color: #000000;">&#40;</span>i2 <span style="color: #008000;">=&gt;</span> i2.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #666666;">&quot;, &quot;</span><span style="color: #000000;">&#41;</span>, <span style="color: #666666;">&quot;<span style="color: #008080; font-weight: bold;">\r</span><span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008080; font-style: italic;">// Beispiel-Ausgabe:</span>
<span style="color: #008080; font-style: italic;">// 1.1.2010, 2.1.2010</span>
<span style="color: #008080; font-style: italic;">// 1.1.2011, 2.1.2011, 3.1.2011</span>
<span style="color: #008080; font-style: italic;">// ...</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2011/10/serializetostring-c-snippets/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2011/10/serializetostring-c-snippets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>c# &#8211; WorkingSetControl / RamControl: Displaying the Working Set size / current RAM usage of an application</title>
		<link>http://familie-ottenhaus.de/simon/blog/2010/11/c-workingsetcontrol-ramcontrol-displaying-the-working-set-size-current-ram-usage-of-an-application/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2010/11/c-workingsetcontrol-ramcontrol-displaying-the-working-set-size-current-ram-usage-of-an-application/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 13:38:42 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[RAM]]></category>
		<category><![CDATA[Working Set]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=1133</guid>
		<description><![CDATA[English Did you ever want to display the Working Set size / current RAM usage of your c# application? If the answer to this question is &#8216;yes&#8217;, here is your solution. If the answer is &#8216;no&#8217; you still might find some usable code snippets in the control. Deutsch Es ist relativ einfach die aktuelle Speicherbelegung [...]]]></description>
			<content:encoded><![CDATA[<p><em>English</em><br />
Did you ever want to display the Working Set size / current RAM usage of your c# application? If the answer to this question is &#8216;yes&#8217;, here is your solution. If the answer is &#8216;no&#8217; you still might find some usable code snippets in the control.</p>
<p><em>Deutsch</em><br />
Es ist relativ einfach die aktuelle Speicherbelegung in einem c# Programm herauszufinden. Ich habe dies Funktionalität in ein kleinen Control verpackt.</p>
<p>Screenshot des Controls:<br />
<img src="http://familie-ottenhaus.de/simon/blog/wp-content/uploads/2010/11/WorkingSetControl.png" alt="WorkingSetControl" title="WorkingSetControl" width="136" height="31" class="alignnone size-full wp-image-1137" /></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1133code14'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p113314"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
</pre></td><td class="code" id="p1133code14"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Windows.Forms</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Threading</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Diagnostics</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> MyProject
<span style="color: #000000;">&#123;</span>
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Control to display the  current WorkingSet size. Aka &quot;RamControl&quot;. Just call Start to start the monitoring.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #FF0000;">class</span> WorkingSetControl <span style="color: #008000;">:</span> Control
    <span style="color: #000000;">&#123;</span>
        Thread t1<span style="color: #008000;">;</span>
        <span style="color: #FF0000;">bool</span> active <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> WorkingSetControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            SetStyle<span style="color: #000000;">&#40;</span>ControlStyles.<span style="color: #0000FF;">OptimizedDoubleBuffer</span>, <span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Start displaying the current WorkingSet size. If you don't call Start you won't see a thing!</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">internal</span> <span style="color: #0600FF;">void</span> Start<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// start only if not started yet</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>t1 <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// although we could use a lambda expression to create this thread don't use one to be .NET 2.0 compatible.</span>
                t1 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Thread<span style="color: #000000;">&#40;</span>run<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// if you *HAVE* to use a lambda expression, fine have fun with your cryptic code:</span>
                <span style="color: #008080; font-style: italic;">/*
                t1 = new Thread(() =&gt;
                {
                    while (active)
                    {
                        Invalidate();
                        Thread.Sleep(100);
                    }
                });
                */</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// set active to true, so our run method does actually run in loops 'n loops 'n loops until active is set to false ==&gt; see Dispose.</span>
                active <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
                t1.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">void</span> run<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>active<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Invalidate<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Thread.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span>100<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Get and draw the WorkingSet size</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;e&quot;&gt;&lt;/param&gt;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnPaint<span style="color: #000000;">&#40;</span>PaintEventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #FF0000;">string</span> ram <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;xxx&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// Only get the WorkingSet size if the control is in active mode.</span>
            <span style="color: #008080; font-style: italic;">// This prevents the control displaying the WorkingSet size of Visual Studio in the designer (which works actually, but is somehow confusing).</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>active<span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #FF0000;">long</span> lngSessMemory <span style="color: #008000;">=</span> Process.<span style="color: #0000FF;">GetCurrentProcess</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">WorkingSet64</span><span style="color: #008000;">;</span>
                ram <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>lngSessMemory<span style="color: #000000;">&#41;</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;0.00&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// do the grphics stuff</span>
            e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span>BackColor<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            e.<span style="color: #0000FF;">Graphics</span>.<span style="color: #0000FF;">DrawString</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;WorkingSet: &quot;</span> <span style="color: #008000;">+</span> ram <span style="color: #008000;">+</span> <span style="color: #666666;">&quot; MB&quot;</span>, Font, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SolidBrush<span style="color: #000000;">&#40;</span>ForeColor<span style="color: #000000;">&#41;</span>, 0, 0<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Lets make sure our thread terminates at some point in time.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;disposing&quot;&gt;&lt;/param&gt;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> Dispose<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span> disposing<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// I know we should wait for the thread to actually funish by using t1.Join() but that would slow down this methob by up to 100ms.</span>
            <span style="color: #008080; font-style: italic;">// If you have any Problems with controls not disposing properly, let me know and send me a solution ;)</span>
            active <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span>disposing<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2010/11/c-workingsetcontrol-ramcontrol-displaying-the-working-set-size-current-ram-usage-of-an-application/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2010/11/c-workingsetcontrol-ramcontrol-displaying-the-working-set-size-current-ram-usage-of-an-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dotfuscator CE + Explizite Schnittstellen- implementierung (Interface) = TypeLoadException: Die Methode GetEnumerator hat keine Implementierung</title>
		<link>http://familie-ottenhaus.de/simon/blog/2010/06/dotfuscator-ce-explizite-schnittstellen-implementierung-interface-typeloadexception-die-methode-getenumerator-hat-keine-implementierung/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2010/06/dotfuscator-ce-explizite-schnittstellen-implementierung-interface-typeloadexception-die-methode-getenumerator-hat-keine-implementierung/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 13:36:49 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Dotfuscator]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=1108</guid>
		<description><![CDATA[Ich verwende Dotfuscator CE (Community Edition) um meine .Net Anwendungen zu schützen. Kürzlich ist dabei ein Fehler aufgetreten: TypeLoadException: Die Methode GetEnumerator hat keine Implementierung Das Problem bestand aber nur nachdem die Anwendung vom Dotfuscator bearbeitet wurde. Vorher funktionierte alles noch prima. Aufgetreten war das Ganze, weil ich in einer Klasse zwei verschiedene IEnumerable&#60;T&#62; implementiert [...]]]></description>
			<content:encoded><![CDATA[<p>Ich verwende Dotfuscator CE (Community Edition) um meine .Net Anwendungen zu schützen. </p>
<p>Kürzlich ist dabei ein Fehler aufgetreten:</p>
<blockquote><p>TypeLoadException: Die Methode GetEnumerator hat keine Implementierung</p></blockquote>
<p>Das Problem bestand aber nur nachdem die Anwendung vom Dotfuscator bearbeitet wurde. Vorher funktionierte alles noch prima.</p>
<p>Aufgetreten war das Ganze, weil ich in einer Klasse zwei verschiedene IEnumerable&lt;T&gt; implementiert hatte.<br />
Beispiel:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1108code16'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p110816"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p1108code16"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> MyClass <span style="color: #008000;">:</span> IEnumerable<span style="color: #008000;">&lt;</span>ClassA<span style="color: #008000;">&gt;</span>, IEnumerable<span style="color: #008000;">&lt;</span>ClassB<span style="color: #008000;">&gt;</span> <span style="color: #000000;">&#123;</span>
...
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>In diesem Fall ist eine sogenannte <a href="http://msdn.microsoft.com/de-de/library/ms173157%28VS.80%29.aspx" target="_blank" class="liexternal">Explizite Schnittstellenimplementierung</a> notwendig. Dies hat der Dotfuscator offensichtlich nicht verstanden. Nachdem ich die Implementierung der Schnittstelle in eine extra Methode ausgelagert hatte und die Explizite Schnittstellenimplementierung entfernt hatte funktionierte alles wieder gut.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2010/06/dotfuscator-ce-explizite-schnittstellen-implementierung-interface-typeloadexception-die-methode-getenumerator-hat-keine-implementierung/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2010/06/dotfuscator-ce-explizite-schnittstellen-implementierung-interface-typeloadexception-die-methode-getenumerator-hat-keine-implementierung/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows XP SP3 + Visual Studio 2010 (c#) = Bluescreen</title>
		<link>http://familie-ottenhaus.de/simon/blog/2010/05/windows-xp-sp3-visual-studio-2010-c-bluescreen/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2010/05/windows-xp-sp3-visual-studio-2010-c-bluescreen/#comments</comments>
		<pubDate>Tue, 25 May 2010 10:53:25 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Bluescreen]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Visual Studio 2010]]></category>
		<category><![CDATA[Windows XP]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=1104</guid>
		<description><![CDATA[Nachdem ich angefangen habe einen Teil meiner Projekte in von VS 2008 nach VS 2010 zu konvertieren musste ich Visual Studio 2010 auch auf allen Entwicklungsrechnern installieren. Die Migration der Projekte und build-skripte verlief erstaunlich problem- und reibungslos. Probleme gab es nur auf dem letzten Windows XP PC. Visual Studio konnte zwar problemlos geöffnet, das [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich angefangen habe einen Teil meiner Projekte in von VS 2008 nach VS 2010 zu konvertieren musste ich Visual Studio 2010 auch auf allen Entwicklungsrechnern installieren. Die Migration der Projekte und build-skripte verlief erstaunlich problem- und reibungslos.</p>
<p>Probleme gab es nur auf dem letzten Windows XP PC. Visual Studio konnte zwar problemlos geöffnet, das Projekt auch gebaut und gestartet werden. Wenn VS 2010 allerdings geschlossen wurde verabschiedete sich Windows XP jedes Mal ausnahmslos mit einem Bluescreen.</p>
<p><strong>Sofortlösung</strong><br />
Die schnellste Lösung war Visual Studio 2010 nicht zu schließen sondern mit dem Task Manager zu beenden. Da dies allerdings nur eine Notlösung war musste ich weiter probieren&#8230;</p>
<p>Das Installieren der von VS 2010 angemahnten &#8220;Windows-Automatisierungs-API&#8221; brachte leider nichts.</p>
<p><strong>Endgültige Lösung</strong><br />
Da VS 2010 WPF (Windows Presentation Foundation) verwendet und diese Hardwarebeschleunigung verwendet beschloss ich das Problem mit einem Grafikkartrenteiberupdate anzugehen. Nahezu unglaublich aber wahr: Der aktuelle GeForce Treiber (197.45) löste das Problem. VS lässt sich nun wieder ohne Absturz schließen.</p>
<p>Es gilt also:<br />
Windows XP SP3<br />
+ Visual Studio 2010 (c#)<br />
+ Neuer Grafikkarten Treiber = <img src='http://familie-ottenhaus.de/simon/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  (Zumindest in meinem Fall)</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2010/05/windows-xp-sp3-visual-studio-2010-c-bluescreen/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2010/05/windows-xp-sp3-visual-studio-2010-c-bluescreen/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>c# &#8211; eigenes Control, Keys.Up, Down, Left, Right: OnKeyDown / OnKeyPress vs. ProcessCmdKey</title>
		<link>http://familie-ottenhaus.de/simon/blog/2009/12/csharp-eigenes-control-keys-up-down-left-right-onkeydown-onkeypress-vs-processcmdkey/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2009/12/csharp-eigenes-control-keys-up-down-left-right-onkeydown-onkeypress-vs-processcmdkey/#comments</comments>
		<pubDate>Wed, 16 Dec 2009 19:06:36 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Down]]></category>
		<category><![CDATA[Keys]]></category>
		<category><![CDATA[Left]]></category>
		<category><![CDATA[OnKeyDown]]></category>
		<category><![CDATA[ProcessCmdKey]]></category>
		<category><![CDATA[Right]]></category>
		<category><![CDATA[Up]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=997</guid>
		<description><![CDATA[Wer ein eigenes Control (Steuerelement) in c# erstellt und dachte, dass er mit OnKeyDown Pfeiltasten erkennen kann ist auf dem Holzweg: View Code CSHARP1 2 3 4 5 6 protected override void OnKeyDown&#40;KeyEventArgs e&#41; &#123; /* wird für Pfeiltasten nicht aufgerufen */ base.OnKeyDown&#40;e&#41;; if &#40;e.KeyCode == Keys.Up&#41; MoveIndex&#40;-1&#41;; &#125; Bei Druck auf die Pfeiltasten (Keys.Up, [...]]]></description>
			<content:encoded><![CDATA[<p>Wer ein eigenes Control (Steuerelement) in c# erstellt und dachte, dass er mit OnKeyDown Pfeiltasten erkennen kann ist auf dem Holzweg:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p997code20'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p99720"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p997code20"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnKeyDown<span style="color: #000000;">&#40;</span>KeyEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">/* wird für Pfeiltasten nicht aufgerufen */</span>
	<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnKeyDown</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">KeyCode</span> <span style="color: #008000;">==</span> Keys.<span style="color: #0000FF;">Up</span><span style="color: #000000;">&#41;</span> MoveIndex<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span>1<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Bei Druck auf die Pfeiltasten (Keys.Up, Keys.Down, Keys.Left, Keys.Right) wird <strong>weder OnKeyDown noch OnKeyPress aufgerufen</strong>.</p>
<p>Die Lösung bringt ProcessCmdKey:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p997code21'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p99721"><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code" id="p997code21"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> ProcessCmdKey<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> Message msg, Keys keyData<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>keyData <span style="color: #008000;">==</span> Keys.<span style="color: #0000FF;">Up</span><span style="color: #000000;">&#41;</span> MoveIndex<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span>1<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">return</span> <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">ProcessCmdKey</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">ref</span> msg, keyData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Hier muss allerdings beachtet werden, dass in keyData auch Strg, Shift und Alt kodiert werden. <em>keyData == Keys.Up</em> ist nur true, wenn keine Steuerungstaste (Strg, Shift, Alt) gleichzeitig gedrückt wurde.</p>
<p>Welche Tasten gedrückt sind lässt sich folgendermaßen herausfinden:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p997code22'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p99722"><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code" id="p997code22"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">bool</span> shift <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>keyData <span style="color: #008000;">&amp;</span> Keys.<span style="color: #0000FF;">Shift</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> control <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>keyData <span style="color: #008000;">&amp;</span> Keys.<span style="color: #0000FF;">Control</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
<span style="color: #FF0000;">bool</span> alt <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>keyData <span style="color: #008000;">&amp;</span> Keys.<span style="color: #0000FF;">Alt</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">!=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
Keys unmodifiedKey <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>keyData <span style="color: #008000;">&amp;</span> Keys.<span style="color: #0000FF;">KeyCode</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2009/12/csharp-eigenes-control-keys-up-down-left-right-onkeydown-onkeypress-vs-processcmdkey/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2009/12/csharp-eigenes-control-keys-up-down-left-right-onkeydown-onkeypress-vs-processcmdkey/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>c#: Win32Exception: Fehler beim Erstellen des Fensterhandles</title>
		<link>http://familie-ottenhaus.de/simon/blog/2009/12/csharp-win32exception-fehler-beim-erstellen-des-fensterhandles/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2009/12/csharp-win32exception-fehler-beim-erstellen-des-fensterhandles/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 16:21:01 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Win32Exception]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=973</guid>
		<description><![CDATA[Wann tritt diese Exception auf? &#8211; Wenn zu viele Steuerelemente erstellt und nicht wieder aufgeräumt wurden. Beispiel View Code CSHARP1 2 3 4 5 6 7 8 9 10 11 12 public partial class Form1 : Form &#123; void ForceException&#40;&#41; &#123; while &#40;true&#41; &#123; Label l = new Label&#40;&#41;; this.Controls.Add&#40;l&#41;; this.Controls.Clear&#40;&#41;; &#125; &#125; &#125; Bei [...]]]></description>
			<content:encoded><![CDATA[<p>Wann tritt diese Exception auf? &#8211; Wenn zu viele Steuerelemente erstellt und nicht wieder aufgeräumt wurden.</p>
<p><strong>Beispiel</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p973code25'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p97325"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code" id="p973code25"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> Form1 <span style="color: #008000;">:</span> Form
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">void</span> ForceException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Label l <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Label<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Bei jedem Schleifendurchlauf wird ein neues Label erstellt. mit this.Controls.Clear(); wird das Label zwar entfernt, aber das Fenster-Handle des Labels existiert weiterhin. Da jeder Prozess nur begrenzt viele Fenster-Handles haben kann sind diese irgendwann aufgebraucht.</p>
<p><strong>Abhilfe</strong></p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p973code26'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p97326"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code" id="p973code26"><pre class="csharp" style="font-family:monospace;">    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> Form1 <span style="color: #008000;">:</span> Form
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">void</span> ForceException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                Label l <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Label<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>l<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                l.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Mit l.Dispose(); werden alle Ressourcen, die das Label reserviert hatte freigegeben. Damit wird auch das Fenster-Handle wieder frei und kann später wieder verwendet werden. Die obige while-Schleife läuft beliebig lange ohne Fehler.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2009/12/csharp-win32exception-fehler-beim-erstellen-des-fensterhandles/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2009/12/csharp-win32exception-fehler-beim-erstellen-des-fensterhandles/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>C#: Strg+C, Strg+V, Strg+X</title>
		<link>http://familie-ottenhaus.de/simon/blog/2009/04/c-strgc-strgv-strgx/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2009/04/c-strgc-strgv-strgx/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 12:24:51 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[HowTo / Anleitung]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Strg+C]]></category>
		<category><![CDATA[Strg+V]]></category>
		<category><![CDATA[Strg+X]]></category>
		<category><![CDATA[Tasten]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=670</guid>
		<description><![CDATA[In einer benutzerfreundlichen Anwendung sollte der Benutzer wenn möglich Strg+C, Strg+V und Strg+X verwenden können. Dies ist einfach zu realisieren: View Code CSHARP1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 [...]]]></description>
			<content:encoded><![CDATA[<p>In einer benutzerfreundlichen Anwendung sollte der Benutzer wenn möglich Strg+C, Strg+V und Strg+X verwenden können.</p>
<p>Dies ist einfach zu realisieren:</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p670code28'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p67028"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="code" id="p670code28"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.ComponentModel</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Data</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Drawing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Windows.Forms</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #FF0000;">class</span> MyForm <span style="color: #008000;">:</span> Form
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnKeyDown<span style="color: #000000;">&#40;</span>KeyEventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Modifiers</span> <span style="color: #008000;">==</span> Keys.<span style="color: #0000FF;">Control</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">KeyCode</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #0600FF;">case</span> Keys.<span style="color: #0000FF;">C</span><span style="color: #008000;">:</span>
					tryCopy<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
					break<span style="color: #008000;">;</span>
				<span style="color: #0600FF;">case</span> Keys.<span style="color: #0000FF;">V</span><span style="color: #008000;">:</span>
					tryPaste<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span> 
					break<span style="color: #008000;">;</span>
				<span style="color: #0600FF;">case</span> Keys.<span style="color: #0000FF;">X</span><span style="color: #008000;">:</span>
					tryCut<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
					break<span style="color: #008000;">;</span>
				<span style="color: #0600FF;">case</span> Keys.<span style="color: #0000FF;">Delete</span><span style="color: #008000;">:</span>
					tryDelete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
					break<span style="color: #008000;">;</span>
				<span style="color: #0600FF;">case</span> Keys.<span style="color: #0000FF;">Right</span><span style="color: #008000;">:</span>
					tryMoveNext<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
					break<span style="color: #008000;">;</span>
				<span style="color: #0600FF;">case</span> Keys.<span style="color: #0000FF;">Left</span><span style="color: #008000;">:</span>
					tryMovePrevious<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
					break<span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnKeyDown</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Nun noch die tryXY-Funktionen implementieren und fertig ist die Tastaturbedienung des Programms.</p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2009/04/c-strgc-strgv-strgx/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2009/04/c-strgc-strgv-strgx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TextControl</title>
		<link>http://familie-ottenhaus.de/simon/blog/2009/01/textcontrol/</link>
		<comments>http://familie-ottenhaus.de/simon/blog/2009/01/textcontrol/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 15:24:32 +0000</pubDate>
		<dc:creator>Simon Ottenhaus</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Control]]></category>
		<category><![CDATA[Label]]></category>
		<category><![CDATA[Text]]></category>

		<guid isPermaLink="false">http://familie-ottenhaus.de/simon/blog/?p=19</guid>
		<description><![CDATA[In c#.Net gibt es einen Label. Dieser ist recht praktisch, solange man nicht weitere Steuerelemente direkt anschließend platzieren möchte.

Die einzige Möglichkeit einen Label zu realisieren, der überhaupt kein Padding hat, ist diesen selbst zu schreiben...]]></description>
			<content:encoded><![CDATA[<p>In c#.Net gibt es einen Label. Dieser ist recht praktisch, solange man nicht weitere Steuerelemente direkt anschließend platzieren möchte.</p>
<p>Die einzige Möglichkeit einen Label zu realisieren, der überhaupt kein Padding hat, ist diesen selbst zu schreiben.</p>

<div class="wp_codebox_msgheader"><span class="right"></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p19code29'); return false;">View Code</a> CSHARP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table width="100%" ><tr id="p1929"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
</pre></td><td class="code" id="p19code29"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">class</span> TextControl <span style="color: #008000;">:</span> Control
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">private</span> Brush brush <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SolidBrush<span style="color: #000000;">&#40;</span>Color.<span style="color: #0000FF;">Black</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">private</span> StringFormat stringFormat<span style="color: #008000;">;</span>
	<span style="color: #0600FF;">private</span> Graphics graphics <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">internal</span> <span style="color: #0600FF;">static</span> StringFormat GetStringFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		StringFormat stringFormat <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StringFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		stringFormat.<span style="color: #0000FF;">Alignment</span> <span style="color: #008000;">=</span> StringAlignment.<span style="color: #0000FF;">Center</span><span style="color: #008000;">;</span>
		stringFormat.<span style="color: #0000FF;">LineAlignment</span> <span style="color: #008000;">=</span> StringAlignment.<span style="color: #0000FF;">Near</span><span style="color: #008000;">;</span>
		stringFormat.<span style="color: #0000FF;">Trimming</span> <span style="color: #008000;">=</span> StringTrimming.<span style="color: #0000FF;">None</span><span style="color: #008000;">;</span>
		stringFormat.<span style="color: #0000FF;">FormatFlags</span> <span style="color: #008000;">=</span> StringFormatFlags.<span style="color: #0000FF;">NoWrap</span> <span style="color: #008000;">|</span> StringFormatFlags.<span style="color: #0000FF;">MeasureTrailingSpaces</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> stringFormat<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> TextControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">stringFormat</span> <span style="color: #008000;">=</span> GetStringFormat<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		graphics <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CreateGraphics</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">TabStop</span> <span style="color: #008000;">=</span> false<span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
	~TextControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		graphics.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnPaint<span style="color: #000000;">&#40;</span>PaintEventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnPaint</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		RePaint<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">void</span> RePaint<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		Graphics g <span style="color: #008000;">=</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">CreateGraphics</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		g.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">BackColor</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		g.<span style="color: #0000FF;">DrawString</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Text</span>, <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Font</span>, brush, <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">ClientRectangle</span>, stringFormat<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnParentChanged<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnParentChanged</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AutoSize</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			DoAutoSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span>.<span style="color: #0000FF;">Browsable</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">true</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #000000;">&#91;</span><span style="color: #000000;">System.<span style="color: #0000FF;">ComponentModel</span></span>.<span style="color: #0000FF;">Category</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Layout&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #FF0000;">bool</span> AutoSize
	<span style="color: #000000;">&#123;</span>
		get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">AutoSize</span><span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
		set <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">AutoSize</span> <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnForeColorChanged<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnForeColorChanged</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		brush.<span style="color: #0000FF;">Dispose</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		brush <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SolidBrush<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">ForeColor</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnTextChanged<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
&nbsp;
		<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnTextChanged</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">AutoSize</span> <span style="color: #008000;">&amp;</span>amp<span style="color: #008000;">;&amp;</span>amp<span style="color: #008000;">;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Parent</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			DoAutoSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">void</span> DoAutoSize<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		RectangleF rf <span style="color: #008000;">=</span> MeasureText<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Text</span>, graphics, stringFormat, <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">Font</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Size</span> <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Size<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>rf.<span style="color: #0000FF;">Width</span>, <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>rf.<span style="color: #0000FF;">Height</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> RectangleF MeasureText<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> text, Graphics g, StringFormat sf, Font font<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>text.<span style="color: #0000FF;">Length</span> <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> 0<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			sf.<span style="color: #0000FF;">SetMeasurableCharacterRanges</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CharacterRange<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> CharacterRange<span style="color: #000000;">&#40;</span>0, text.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			Region<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> stringRegions <span style="color: #008000;">=</span> g.<span style="color: #0000FF;">MeasureCharacterRanges</span><span style="color: #000000;">&#40;</span>text, font, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RectangleF<span style="color: #000000;">&#40;</span>0, 0, 1000, 100<span style="color: #000000;">&#41;</span>, sf<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">return</span> stringRegions<span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</span>.<span style="color: #0000FF;">GetBounds</span><span style="color: #000000;">&#40;</span>g<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">else</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> RectangleF<span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> PointF<span style="color: #000000;">&#40;</span>0, 0<span style="color: #000000;">&#41;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> SizeF<span style="color: #000000;">&#40;</span>0, 0<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">float</span> getTextLength<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> Text, Graphics g, StringFormat sf, Font font<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		RectangleF rf <span style="color: #008000;">=</span> MeasureText<span style="color: #000000;">&#40;</span>Text, g, sf, font<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">return</span> rf.<span style="color: #0000FF;">Width</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">int</span> GetMaxTextByLength<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> text, <span style="color: #FF0000;">int</span> maxLength, Graphics g, StringFormat sf, Font font<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>getTextLength<span style="color: #000000;">&#40;</span>text, g, sf, font<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;=</span> maxLength<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			<span style="color: #0600FF;">return</span> text.<span style="color: #0000FF;">Length</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> parts <span style="color: #008000;">=</span> text.<span style="color: #0000FF;">Split</span><span style="color: #000000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">char</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #666666;">' '</span> <span style="color: #000000;">&#125;</span>, StringSplitOptions.<span style="color: #0000FF;">None</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #FF0000;">int</span> len <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
		<span style="color: #FF0000;">string</span> current <span style="color: #008000;">=</span> parts<span style="color: #000000;">&#91;</span>0<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
		len <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>getTextLength<span style="color: #000000;">&#40;</span>current, g, sf, font<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>len <span style="color: #008000;">&amp;</span>gt<span style="color: #008000;">;</span> maxLength<span style="color: #000000;">&#41;</span> <span style="color: #0600FF;">return</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
		<span style="color: #FF0000;">int</span> n <span style="color: #008000;">=</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span>len <span style="color: #008000;">&amp;</span>lt<span style="color: #008000;">;</span> maxLength<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			current <span style="color: #008000;">+=</span> <span style="color: #666666;">&quot; &quot;</span> <span style="color: #008000;">+</span> parts<span style="color: #000000;">&#91;</span>n<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
			n<span style="color: #008000;">++;</span>
			len <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span><span style="color: #000000;">&#41;</span>getTextLength<span style="color: #000000;">&#40;</span>current, g, sf, font<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
		<span style="color: #0600FF;">return</span> len<span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnAutoSizeChanged<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnAutoSizeChanged</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">OnTextChanged</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://familie-ottenhaus.de/simon/blog/2009/01/textcontrol/" target="_blank" class="liimagelink"><img src="http://familie-ottenhaus.de/simon/blog/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://familie-ottenhaus.de/simon/blog/2009/01/textcontrol/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

