<?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>oliana.de &#187; C#</title>
	<atom:link href="http://oliana.de/blog/tag/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://oliana.de/blog</link>
	<description>Das Problem zwischen Stuhl und Bildschirm</description>
	<lastBuildDate>Mon, 12 Apr 2010 14:20:55 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Fehler in der Fensterbehandlung von WPF</title>
		<link>http://oliana.de/blog/2009/10/02/fehler-in-der-fensterbehandlung-von-wpf-2/</link>
		<comments>http://oliana.de/blog/2009/10/02/fehler-in-der-fensterbehandlung-von-wpf-2/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 08:41:46 +0000</pubDate>
		<dc:creator>Denis</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://oliana.de/blog/2009/10/02/fehler-in-der-fensterbehandlung-von-wpf-2/</guid>
		<description><![CDATA[Gerade habe ich einen kleinen Fehler in WPF entdeckt. Scheinbar ist es so, dass Fensterinstanzen bei der Instanziierung schon zur WindowCollection hinzugefügt werden und nicht erst wenn Sie geöffnet werden. Dadurch muss man Sie erst entfernen, bevor man das Programm beenden kann, da es ansonsten denkt, dass noch ein Fenster offen ist.

Entdeckt habe ich das [...]]]></description>
			<content:encoded><![CDATA[<p>Gerade habe ich einen kleinen Fehler in WPF entdeckt. Scheinbar ist es so, dass Fensterinstanzen bei der Instanziierung schon zur WindowCollection hinzugefügt werden und nicht erst wenn Sie geöffnet werden. Dadurch muss man Sie erst entfernen, bevor man das Programm beenden kann, da es ansonsten denkt, dass noch ein Fenster offen ist.</p>
<p><span id="more-252"></span></p>
<p>Entdeckt habe ich das ganze bei einem Projekt in dem ich eine neue Instanz eines Fensters erstellt habe, ohne es zu öffnen (über die Gründe will ich jetzt mal nichts sagen – ich weiß, dass das an sich ne blöde Idee ist…). Nachdem ich das Programm gestartet habe, konnte ich zwar alle Fenster schließen, aber der Prozess lief immer weiter.</p>
<p>Nach etwas debuggen habe ich dann herausgefunden, dass immer noch eine Referenz zum Fenster vorhanden ist, obwohl dieses gar nicht mehr existiert. Dadurch kann das Programm natürlich nicht beendet werden, da es denkt, das noch irgendwo ein Fenster offen ist.</p>
<p>Die Referenz zum Fenster in der WindowCollection der Anwendung wird scheinbar dann entfernt, wenn Window.Close() aufgerufen wird.</p>
<p>Ein sehr interessantes Phänomen, auf das man erst mal kommen muss…</p>
<h2>Update:</h2>
<p>Nachdem ich dafür einen Bug bei Microsoft Connect erstellt habe, kam nun die Antwort, dass das Verhalten “bei Design” ist. Komisch, ist aber so…</p>
<p>Zitat:</p>
<blockquote><p>This behavior is probably by design. Application has a property called &#8220;ShutdownMode&#8221; that has a default value of OnLastWindowClose. Creating a window is sufficient to register it for keeping the application alive, even if it is never shown.<br />
Depending on your scenario another value for ShutdownMode may be appropriate.<br />
Hope that helps,</p></blockquote>
<div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:853aab67-2a47-4827-94f9-0cb928419e86" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">Technorati-Tags: <a rel="tag" href="http://technorati.com/tags/software">software</a>,<a rel="tag" href="http://technorati.com/tags/c%23">c#</a>,<a rel="tag" href="http://technorati.com/tags/wpf">wpf</a></div>
]]></content:encoded>
			<wfw:commentRss>http://oliana.de/blog/2009/10/02/fehler-in-der-fensterbehandlung-von-wpf-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Maskedtextbox in WPF implementieren</title>
		<link>http://oliana.de/blog/2009/07/29/maskedtextbox-in-wpf-implementieren/</link>
		<comments>http://oliana.de/blog/2009/07/29/maskedtextbox-in-wpf-implementieren/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 13:21:57 +0000</pubDate>
		<dc:creator>Denis</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://oliana.de/blog/?p=237</guid>
		<description><![CDATA[Heute beschreibe ich mal, wie man in WPF ein Control erstellt, dass von TextBox erbt und die Funktionalität einer Maskedtextbox bietet. Als ich vor kurzem diese Funktionalität brauchte hat sich herausgestellt, dass das ganze innerhalb von kurzer Zeit erledigt werden kann.
 


Zunächst erzeugt man in Visual Studio ein entsprechendes Projekt mit der Vorlage WPF-Benutzersteuerelementbibliothek. 
In [...]]]></description>
			<content:encoded><![CDATA[<p>Heute beschreibe ich mal, wie man in WPF ein Control erstellt, dass von TextBox erbt und die Funktionalität einer Maskedtextbox bietet. Als ich vor kurzem diese Funktionalität brauchte hat sich herausgestellt, dass das ganze innerhalb von kurzer Zeit erledigt werden kann.</p>
<p> <span id="more-237"></span>
</p>
<ol>
<li>Zunächst erzeugt man in Visual Studio ein entsprechendes Projekt mit der Vorlage WPF-Benutzersteuerelementbibliothek. </li>
<li>In diesem Projekt kann man das automatisch erzeugte UserControl1 guten Gewissens entfernen (wir wollen ja ein WPF-Steuerelement erstellen). </li>
<li>Dafür muss man unser WPF-Steuerelement hinzufügen. (Einfügen –&gt; neues Element –&gt; Benutzersteuerelement) </li>
<li>Jetzt geht es darum, aus dem Usercontrol ein Steuerelement zu machen, welches von der Standard-TextBox erbt, damit man die ganzen Standard Geschichten schon fertig hat. Dazu einfach im XAML-Code UserControl durch TextBox ersetzen, und alle Attribute außer den namespaces und dem Klassennamen entfernen, so dass es in etwa so ausschaut:
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5a579f08-8001-485d-945e-e246591268a5" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">TextBox </span><span style="color: #FF0000;">x:Class</span><span style="color: #0000FF;">="Denis.WPF_Controls.MaskedTextBoxWPF"</span><span style="color: #FF0000;">
    xmlns</span><span style="color: #0000FF;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span><span style="color: #FF0000;">
    xmlns:x</span><span style="color: #0000FF;">="http://schemas.microsoft.com/winfx/2006/xaml"</span><span style="color: #FF0000;">
</span><span style="color: #0000FF;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
<p>Dadurch sagen wir einfach, dass wir ein Steuerelement erzeugen dass von TextBox erbt. Da es ja auch noch eine entsprechende CodeDatei gibt müssen wir dort ebenfalls sagen, dass wir nicht mehr die partielle Klasse UserControl erweitern, sondern Textbox:</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:b2df5a21-75f0-4068-abcb-6f0d5ec7ca91" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">partial</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> MaskedTextBoxWPF : UserControl
</span><span style="color: #008000;">//</span><span style="color: #008000;">ersetzen durch</span><span style="color: #008000;">
</span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">partial</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> MaskedTextBoxWPF : TextBox</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</li>
<li>Jetzt brauchen wir noch ein paar Events die wir behandeln um abzufangen wenn Text eingegeben, gelöscht und eingefügt (copy/paste) wird. Dazu einfach den XAML-Code so erweitern:
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:a1c6b245-442f-47bb-93ea-299407f12939" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">&lt;</span><span style="color: #800000;">TextBox </span><span style="color: #FF0000;">x:Class</span><span style="color: #0000FF;">="Denis.WPF_Controls.MaskedTextBoxWPF"</span><span style="color: #FF0000;">
    xmlns</span><span style="color: #0000FF;">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span><span style="color: #FF0000;">
    xmlns:x</span><span style="color: #0000FF;">="http://schemas.microsoft.com/winfx/2006/xaml"</span><span style="color: #FF0000;">
    DataObject.Pasting</span><span style="color: #0000FF;">="TextBox_Pasting"</span><span style="color: #FF0000;">
    PreviewTextInput</span><span style="color: #0000FF;">="TextBox_PreviewTextInput"</span><span style="color: #FF0000;">
    KeyDown</span><span style="color: #0000FF;">="TextBox_KeyDown"</span><span style="color: #FF0000;">
</span><span style="color: #0000FF;">/&gt;</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</li>
<li>Als erstes brauchen wir eine Klassen-Variable, welche den MaskedTextBoxProvider enthält (wofür ein Verweis auf SystemComponentModel benötigt wird). Diese wird dann im Konstruktor mit einer Standardmaske gefüllt und dann initialisiert:
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:5f0af161-7a69-49c0-a8fc-d951b44b6ddf" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">MaskedTextProvider mktProvider;

</span><span style="color: #0000FF;">public</span><span style="color: #000000;"> MaskedTextBoxWPF()
{
    InitializeComponent();
    mktProvider </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> MaskedTextProvider(</span><span style="color: #800000;">"</span><span style="color: #800000;">???</span><span style="color: #800000;">"</span><span style="color: #000000;">);
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</li>
<li>Außerdem geben wir die Mask-Eigenschaft nach außen weiter, lassen die im Designer bearbeiten und geben auch ne kleine Doku für das Bearbeiten im Designer an:
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:72080bea-049c-46cb-99e5-e8c76560a2cf" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #000000;">[Browsable(</span><span style="color: #0000FF;">true</span><span style="color: #000000;">)]
[DesignOnly(</span><span style="color: #0000FF;">true</span><span style="color: #000000;">)]
[Description(</span><span style="color: #800000;">"</span><span style="color: #800000;">0 Ziffer - erforderlich; 9 Ziffer oder Leerzeichen - opt.;</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;">
          </span><span style="color: #800000;">"</span><span style="color: #800000;">L Buchstabe - erforderlich; ? Buchstabe - opt.</span><span style="color: #800000;">"</span><span style="color: #000000;">)]
</span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">string</span><span style="color: #000000;"> Mask
{
  </span><span style="color: #0000FF;">get</span><span style="color: #000000;">
  {
      </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> mktProvider.Mask;
  }
  </span><span style="color: #0000FF;">set</span><span style="color: #000000;">
  {
      mktProvider </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> MaskedTextProvider(value);
      Text </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">""</span><span style="color: #000000;">;
  }
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</li>
<li>Als letztes müssen wir noch die Events mit Code füllen.Im PreviewTextInput-Ereignis prüfen wir, ob der Buschstabe hinzugefügt werden darf und brechen ggf. ab.Im Pasting-Ereignis machen wir das selbe mit eingefügtem Text und das KeyDown-Ereignis ist dafür da den Text im MaskedTextBoxProvider aktuell zu halten (falls z.B. was gelöscht wird).
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:57F11A72-B0E5-49c7-9094-E3A15BD5B5E6:31ca2506-5b5a-4b31-a9ab-e319fafc8016" class="wlWriterEditableSmartContent">
<pre style="background-color:#FFFFFF;overflow: auto;"><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> TextBox_PreviewTextInput(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, TextCompositionEventArgs e)
{
  </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (mktProvider.Add(e.Text) </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">)
  {
      e.Handled </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">;
  }
}

</span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> TextBox_Pasting(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, DataObjectPastingEventArgs e)
{
  </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (e.DataObject.GetDataPresent(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(String)))
  {
      String text </span><span style="color: #000000;">=</span><span style="color: #000000;"> (String)e.DataObject.GetData(</span><span style="color: #0000FF;">typeof</span><span style="color: #000000;">(String));
      </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (mktProvider.Add(text) </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">)
      {
          e.CancelCommand();
      }
  }
  </span><span style="color: #0000FF;">else</span><span style="color: #000000;"> e.CancelCommand();
}

</span><span style="color: #0000FF;">private</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> TextBox_KeyDown(</span><span style="color: #0000FF;">object</span><span style="color: #000000;"> sender, KeyEventArgs e)
{
  mktProvider.Clear();
  mktProvider.Add(Text);
}</span></pre>
<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http://dunnhq.com --></div>
</li>
</ol>
<p>So, das war’s schon. Man könnte das ganze noch etwas schöner machen, indem man wie bei WinForms die Eingabemaske anzeigt, aber die Funktionalität ist vorhanden und kann so benutzt werden.</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:4859a4d6-694a-46ce-9087-e5144c0cfff3" class="wlWriterEditableSmartContent">Technorati-Tags: <a href="http://technorati.com/tags/WPF" rel="tag">WPF</a>,<a href="http://technorati.com/tags/C%23" rel="tag">C#</a></div>
]]></content:encoded>
			<wfw:commentRss>http://oliana.de/blog/2009/07/29/maskedtextbox-in-wpf-implementieren/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ConnectionString f&#252;r SQL Server CE zum Zugriff auf eine Netzwerkfreigabe</title>
		<link>http://oliana.de/blog/2008/10/05/connectionstring-fr-sql-server-ce-zum-zugriff-auf-eine-netzwerkfreigabe/</link>
		<comments>http://oliana.de/blog/2008/10/05/connectionstring-fr-sql-server-ce-zum-zugriff-auf-eine-netzwerkfreigabe/#comments</comments>
		<pubDate>Sun, 05 Oct 2008 16:09:35 +0000</pubDate>
		<dc:creator>Denis</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SQL Server CE]]></category>

		<guid isPermaLink="false">http://oliana.de/blog/?p=144</guid>
		<description><![CDATA[Ich arbeite gerade an einem kleinen Tool dass auf dem SQL Server CE basiert. Dabei soll auf eine Datei zugegriffen werden, die auf einer Netzwerkfreigabe liegt, welche nicht als Laufwerk eingebunden ist. Mit dem generierten Connectionstring funktioniert dies leider nicht, aber endlich habe ich die Lösung gefunden:

Der generierte Connectionstring hat das Format:
Data Source=&#124;DataDirectory&#124;Pfad
Bei diesem Format [...]]]></description>
			<content:encoded><![CDATA[<p>Ich arbeite gerade an einem kleinen Tool dass auf dem SQL Server CE basiert. Dabei soll auf eine Datei zugegriffen werden, die auf einer Netzwerkfreigabe liegt, welche nicht als Laufwerk eingebunden ist. Mit dem generierten Connectionstring funktioniert dies leider nicht, aber endlich habe ich die Lösung gefunden:</p>
<p><span id="more-144"></span></p>
<p>Der generierte Connectionstring hat das Format:</p>
<pre>Data Source=|DataDirectory|Pfad</pre>
<p>Bei diesem Format bezeichnet “|Datadirectory|” einen Platzhalter der während der Ausführung ersetzt wird. Dies ist z.B. dann der Fall, wenn die Anwendung per ClickOnce verteilt wird und die Datenbankdatei durch das Setup im automatisch angelegten Daten-Verzeichnis abgelegt wird. Wenn man diesen verwendet, sollte man keinen absoluten, sondern nur einen relativen Pfad angeben.</p>
<p>Will man einen absoluten Pfad (wie z.B. ein Verzeichnis einer Netzwerkfreigabe im Format <a href="file://\\Computer\Freigabe\Verzeichnis">\\Computer\Freigabe\Verzeichnis</a>) kann man dieses Format verwenden:</p>
<pre>Data Source=Pfad</pre>
<p>So einfach kann es gehen…</p>
]]></content:encoded>
			<wfw:commentRss>http://oliana.de/blog/2008/10/05/connectionstring-fr-sql-server-ce-zum-zugriff-auf-eine-netzwerkfreigabe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatische Höhe für Labels im Compact Framework auf dem Pocket PC</title>
		<link>http://oliana.de/blog/2008/05/27/automatische-hohe-fur-labels-im-compact-framework-auf-dem-pocket-pc/</link>
		<comments>http://oliana.de/blog/2008/05/27/automatische-hohe-fur-labels-im-compact-framework-auf-dem-pocket-pc/#comments</comments>
		<pubDate>Tue, 27 May 2008 19:50:18 +0000</pubDate>
		<dc:creator>Denis</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Windows Mobile]]></category>
		<category><![CDATA[.Net CF]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://oliana.de/blog/?p=94</guid>
		<description><![CDATA[Für ein kleines Projekt für Windows CE habe ich eine Methode gesucht um die Höhe eines Labels anhand des Inhalts automatisch zu setzen. Dabei habe ich hier eine Lösung in Visual Basic gefunden. Diese Lösung ist eigentlich recht elegant, da Sie API-Funktionen benutzt um das Rectangle zu zeichnen und die Höhe genau so zu bestimmen [...]]]></description>
			<content:encoded><![CDATA[<p>Für ein kleines Projekt für Windows CE habe ich eine Methode gesucht um die Höhe eines Labels anhand des Inhalts automatisch zu setzen. Dabei habe ich <a href="http://gps678.com/17/e1e89d7b8a1ab012.html" target="_blank">hier</a> eine Lösung in Visual Basic gefunden. Diese Lösung ist eigentlich recht elegant, da Sie API-Funktionen benutzt um das Rectangle zu zeichnen und die Höhe genau so zu bestimmen wie Sie auch später im Formular erscheinen würde wenn man z.B. den Text in ein Textfeld schreiben würde.</p>
<p>Hier eine Übersetzung in C#:<span id="more-94"></span></p>
<div>
<div style="border-style: none; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">using</span> System;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">using</span> System.Windows.Forms;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">using</span> System.Runtime.InteropServices;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #0000ff;">using</span> System.Drawing;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #0000ff;">class</span> Helper</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">{</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">struct</span> RECT</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Left;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Top;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Right;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> Bottom;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> DT_CALCRECT = 1024;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> DT_CENTER = 1;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> DT_LEFT = 0;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> DT_RIGHT = 2;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> DT_TOP = 0;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">const</span> <span style="color: #0000ff;">int</span> DT_WORDBREAK = 16;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    [DllImport(<span style="color: #006080;">"coredll.dll"</span>, CharSet = CharSet.Unicode,</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">        SetLastError = <span style="color: #0000ff;">true</span>)]</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span> DeleteObject(IntPtr hObject);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    [DllImport(<span style="color: #006080;">"coredll.dll"</span>, CharSet = CharSet.Unicode,</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        SetLastError = <span style="color: #0000ff;">true</span>)]</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> <span style="color: #0000ff;">int</span> DrawText(IntPtr hdc, <span style="color: #0000ff;">string</span> lpStr,</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">int</span> nCount, <span style="color: #0000ff;">ref</span> RECT lpRect, <span style="color: #0000ff;">int</span> wFormat);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    [DllImport(<span style="color: #006080;">"coredll.dll"</span>, CharSet = CharSet.Unicode,</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        SetLastError = <span style="color: #0000ff;">true</span>)]</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">extern</span> IntPtr SelectObject(IntPtr hdc,</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        IntPtr hObject);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #008000;">/// &lt;summary&gt;</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #008000;">/// Ändert die Höhe des Labels so, dass der Inhalt genau </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #008000;">/// reinpasst.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #008000;">/// &lt;/summary&gt;</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #008000;">/// &lt;param name="label"&gt;Label dessen Höhe angepasst werden soll.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    <span style="color: #008000;">/// &lt;/param&gt;</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span> AutoSizeLabelHeight(Label label)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        RECT uRECT = <span style="color: #0000ff;">new</span> RECT();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">try</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">        {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">            <span style="color: #008000;">/*****************************************************</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            * Create a Graphics object. We need a Graphics object </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">            * so we can get a handle to a Device Context to be used</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            * later in the DrawText API. However the Label control </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">            * in CF2.0 does not support the CreateGraphics method,</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            * so create the Graphics object from the form on which </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">            * the Label is located.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            * Note: This can cause an exception when this routine </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">            * is called from a Form's Resize event. Probably because</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            * the form is not fully initialised and the Resize event</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">            * may be called one or more times during form</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            * initialisation. Therefore, the entire routine is wrapped</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">            * in a Try/Catch block.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">            *****************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">            Graphics objGraphics = label.TopLevelControl.CreateGraphics();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">            <span style="color: #008000;">// Get the handle to the Device Context of the Graphics object</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            IntPtr hDc = objGraphics.GetHdc();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">            {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #008000;">// Get the handle to the Font of the Label</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                IntPtr hFont = label.Font.ToHfont();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                <span style="color: #008000;">// Apply the Font to the Graphics object</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                IntPtr hFontOld = SelectObject(hDc, hFont);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #008000;">// Set the initial size of the Rect</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                uRECT.Right = label.Width - 2;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                <span style="color: #008000;">// Build the base format</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #0000ff;">int</span> lFormat = DT_CALCRECT | DT_WORDBREAK | DT_TOP;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #008000;">/*****************************************************</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">                 * Adjust the format to the Label's text alignment.</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">                 * Note: This probably isn't necessary as the horizontal </span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">                 * alignment of text shouldn't affect the text</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;"><span style="color: #008000;">                 * height calculation. But just in case...</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;"><span style="color: #008000;">                 *****************************************************/</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #0000ff;">switch</span> (label.TextAlign)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                    <span style="color: #0000ff;">case</span> ContentAlignment.TopLeft:</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                        lFormat = lFormat | DT_LEFT;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                        <span style="color: #0000ff;">break</span>;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                    <span style="color: #0000ff;">case</span> ContentAlignment.TopCenter:</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                        lFormat = lFormat | DT_CENTER;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                        <span style="color: #0000ff;">break</span>;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                    <span style="color: #0000ff;">case</span> ContentAlignment.TopRight:</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                        lFormat = lFormat | DT_RIGHT;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                        <span style="color: #0000ff;">break</span>;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                <span style="color: #008000;">// Calculate the Rect of the text</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #0000ff;">if</span> (DrawText(hDc, label.Text, -1, <span style="color: #0000ff;">ref</span> uRECT, lFormat)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                    != 0)</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                    <span style="color: #008000;">// Success</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                    <span style="color: #008000;">// Apply the new height to the label</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                    label.Height = uRECT.Bottom + 2;</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #008000;">// Cleanup</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                <span style="color: #008000;">// Set the Font of the Graphics object back to original</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                SelectObject(hDc, hFontOld);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">                <span style="color: #008000;">// Delete the handle to the Font of the Label</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">                DeleteObject(hFont);</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            <span style="color: #008000;">// Clean up the Graphics object</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">            objGraphics.Dispose();</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">        }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        <span style="color: #0000ff;">catch</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">        {</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">            <span style="color: #008000;">// Do nothing</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">            <span style="color: #008000;">//Debug.WriteLine("AutoSizeLabelHeight failed.")</span></pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">        }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: white;">    }</pre>
<pre style="border-style: none; margin: 0em; padding: 0px; overflow: visible; font-size: 8pt; width: 100%; color: black; line-height: 12pt; font-family: consolas,'Courier New',courier,monospace; background-color: #f4f4f4;">}</pre>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oliana.de/blog/2008/05/27/automatische-hohe-fur-labels-im-compact-framework-auf-dem-pocket-pc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Registerkarte zum Outlook Optionen-Dialog hinzuf&#252;gen</title>
		<link>http://oliana.de/blog/2008/04/09/registerkarte-zum-outlook-optionen-dialog-hinzufgen/</link>
		<comments>http://oliana.de/blog/2008/04/09/registerkarte-zum-outlook-optionen-dialog-hinzufgen/#comments</comments>
		<pubDate>Wed, 09 Apr 2008 22:02:41 +0000</pubDate>
		<dc:creator>Denis</dc:creator>
				<category><![CDATA[Programmierung]]></category>
		<category><![CDATA[Add-In]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Office 2007]]></category>
		<category><![CDATA[Outlook]]></category>

		<guid isPermaLink="false">http://oliana.de/blog/2008/04/09/registerkarte-zum-outlook-optionen-dialog-hinzufgen/</guid>
		<description><![CDATA[Nachdem ich jetzt ca. 1 Std. gebraucht habe um herauszufinden wie es geht beschreibe ich das einfache Verfahren.

Zunächst fügt man seinem Outlook Add-In Projekt ein Benutzersteuerelement hinzu welches die Registerkarte die man später im Optionen-Dialog haben möchte darstellt. Ich habe dieses in diesem Beispiel ctlOptionen genannt. Wichtig ist, dass man die erste Zeile (&#8221; &#8230; [...]]]></description>
			<content:encoded><![CDATA[<p>Nachdem ich jetzt ca. 1 Std. gebraucht habe um herauszufinden wie es geht beschreibe ich das einfache Verfahren.</p>
<p><span id="more-75"></span><br />
Zunächst fügt man seinem Outlook Add-In Projekt ein Benutzersteuerelement hinzu welches die Registerkarte die man später im Optionen-Dialog haben möchte darstellt. Ich habe dieses in diesem Beispiel ctlOptionen genannt. Wichtig ist, dass man die erste Zeile (&#8221; &#8230; ComVisible(true)&#8221;) hinzufügt, da das Steuerelement ansonsten nicht als ActiveX COM Element sichtbar ist. (Dies war übrigens auch mein großes Problem, aber da muss man erst einmal ohne Fehlermeldung drauf kommen&#8230; <a href="http://ahmed0192.blogspot.com/2006/01/adding-new-page-to-outlook-options.html">Hier</a> habe ich endlich die Lösung gefunden.)
</p>
<p>Ausserdem habe ich <a href="http://blog.irm.se/blogs/eric/archive/2006/12/22/Adding-a-Property-Page-to-Oulook-2007-Options-Dialog.aspx">hier</a> eine Methode gefunden um das PropertyPageSite Objekt zu bekommen welches man braucht um das Optionen Formular durch aufrufen des OnStatusChange Ereignisses darüber zu benachrichtigen, dass sich etwas in den Optionen geändert hat. Es sollte beachtet werden, dass in diesem Beispiel beim Ändern von Einstellungen die isDirty-Variable über die entsprechende Eigenschaft auf true gesetzt werden muss, damit das Optionen-Formular benachrichtigt wird.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">[System.Runtime.InteropServices.ComVisible(<span style="color: #0000ff">true</span>)]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">partial</span> <span style="color: #0000ff">class</span> ctlOptionen : UserControl,
    Microsoft.Office.Interop.Outlook.PropertyPage
{
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> isDirty = <span style="color: #0000ff">false</span>;
    <span style="color: #0000ff">private</span> Microsoft.Office.Interop.Outlook.PropertyPageSite site;

    <span style="color: #0000ff">public</span> ctlOptionen()
    {
        InitializeComponent();
    }

    <span style="color: #cc6633">#region</span> PropertyPageSite Objekt holen
    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Hier wird die entpsrechende PropertyPageSite geholt, bei der das OnStatusChange()</span>
    <span style="color: #008000">/// Ereignis ausgelöst wird um das Optionen-Formular zu benachrichtigen, dass etwas</span>
    <span style="color: #008000">/// geändert wurde.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name="sender"&gt;&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name="e"&gt;&lt;/param&gt;</span>
    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> ctlOptionen_Load(<span style="color: #0000ff">object</span> sender, EventArgs e)
    {
        Type type = <span style="color: #0000ff">typeof</span>(UserControl);
        Type oleType = type.Assembly.GetType(
            <span style="color: #006080">"System.Windows.Forms.UnsafeNativeMethods+IOleObject"</span>);
        <span style="color: #0000ff">if</span> (oleType == <span style="color: #0000ff">null</span>) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> InvalidOperationException(
            <span style="color: #006080">"Could not get 'System.Windows.Forms.UnsafeNativeMethods+IOleObject'."</span>);

        System.Reflection.MethodInfo method =
            oleType.GetMethod(<span style="color: #006080">"GetClientSite"</span>);
        <span style="color: #0000ff">if</span> (method == <span style="color: #0000ff">null</span>) <span style="color: #0000ff">throw</span> <span style="color: #0000ff">new</span> InvalidOperationException(
            <span style="color: #006080">"Could not get method 'IOleObject.GetClientSite'."</span>);

        site = method.Invoke(<span style="color: #0000ff">this</span>, <span style="color: #0000ff">null</span>) <span style="color: #0000ff">as</span>
            Microsoft.Office.Interop.Outlook.PropertyPageSite;
    }
    <span style="color: #cc6633">#endregion</span>

    <span style="color: #cc6633">#region</span> PropertyPage Member

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Wird aufgerufen wenn die gemachten Änderungen gespeichert werden sollen </span>
    <span style="color: #008000">/// (Klick auf OK bzw. Übernehmen)</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Apply()
    {
    }
    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Gibt true zurück, wenn die Optionen der Seite sich geändert haben. </span>
    <span style="color: #008000">/// Wird von Outlook benutzt um zu entscheiden ob der Übernehmen-Button aktiviert ist.</span>
    <span style="color: #008000">/// Beim setzen wird hier das Optionen-Formular benachrichtigt, dass sich etwas </span>
    <span style="color: #008000">/// geändert hat.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    [Browsable(<span style="color: #0000ff">false</span>)]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">bool</span> Dirty
    {
        get { <span style="color: #0000ff">return</span> isDirty; }
        set
        {
            <span style="color: #0000ff">if</span> (isDirty != <span style="color: #0000ff">value</span>)
            {
                isDirty = <span style="color: #0000ff">value</span>;
                <span style="color: #0000ff">if</span> (site != <span style="color: #0000ff">null</span>) site.OnStatusChange();
            }
        }
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Hier kann man eine Hilfedatei angeben die mit dieser Seite verknüpft ist.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name="HelpFile"&gt;&lt;/param&gt;</span>
    <span style="color: #008000">/// &lt;param name="HelpContext"&gt;&lt;/param&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> GetPageInfo(<span style="color: #0000ff">ref</span> <span style="color: #0000ff">string</span> HelpFile, <span style="color: #0000ff">ref</span> <span style="color: #0000ff">int</span> HelpContext)
    {
    }

    <span style="color: #cc6633">#endregion</span>
}</pre>
</div>
<p>Als nächstes fügt man einen Ereignishandler (Das ist tatsächlich die deutsche Übersetzung laut MSDN&#8230;) für das OptionPagesAdd-Event hinzu. Dieses Ereignis wird jedes mal angestoßen wenn der Optionen-Dialog geöffnet wird. Dieser kann gut in der ThisAddIn_Startup Methode der ThisAddIn-Klasse untergebracht werden.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">Application.OptionsPagesAdd += <span style="color: #0000ff">new</span> Microsoft.Office.Interop.Outlook
    .ApplicationEvents_11_OptionsPagesAddEventHandler
        (Application_OptionsPagesAdd);</pre>
</div>
<p>Dementsprechend wird auch die Methode erstellt welche dann nichts anderes tut als die Registerkarte hinzuzufügen.</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff">void</span> Application_OptionsPagesAdd
    (Microsoft.Office.Interop.Outlook.PropertyPages Pages)
{
    Pages.Add(<span style="color: #0000ff">new</span> ctlOptionen(), <span style="color: #006080">"Meine Optionen"</span>);
}</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oliana.de/blog/2008/04/09/registerkarte-zum-outlook-optionen-dialog-hinzufgen/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WMI-Informationen mit C# auslesen</title>
		<link>http://oliana.de/blog/2008/03/21/wmi-informationen-mit-c-auslesen/</link>
		<comments>http://oliana.de/blog/2008/03/21/wmi-informationen-mit-c-auslesen/#comments</comments>
		<pubDate>Fri, 21 Mar 2008 16:01:09 +0000</pubDate>
		<dc:creator>Denis</dc:creator>
				<category><![CDATA[Allgemein]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Visual Studio 2008]]></category>

		<guid isPermaLink="false">http://oliana.de/blog/2008/03/21/wmi-informationen-mit-c-auslesen/</guid>
		<description><![CDATA[Ich brauchte für den MAC-Switcher eine einfache Möglichkeit den Namen der Netzwerkverbindungen wie er in der Systemsteuerung angezeigt wird auszulesen. Mit Hilfe von WMI ist dies unglaublich einfach.


Zunächst muss man wissen was man sucht. Was WMI alles zur Verfügung stellt kann man hier in der msdn nachlesen.
Dann baut man einen string zusammen der die Form [...]]]></description>
			<content:encoded><![CDATA[<p>Ich brauchte für den <a href="http://oliana.de/blog/programme/mac-switcher/">MAC-Switcher</a> eine einfache Möglichkeit den Namen der Netzwerkverbindungen wie er in der Systemsteuerung angezeigt wird auszulesen. Mit Hilfe von WMI ist dies unglaublich einfach.</p>
<p><span id="more-44"></span></p>
<ol>
<li>Zunächst muss man wissen was man sucht. Was WMI alles zur Verfügung stellt kann man <a href="http://msdn2.microsoft.com/en-us/library/aa394084(VS.85).aspx">hier in der msdn</a> nachlesen.</li>
<li>Dann baut man einen string zusammen der die Form einer SQL-Query hat.</li>
<li>Als nächstes benutzt man einen ManagementObjectSearcher um die Daten zu suchen. Dieser gibt eine Collection mit den gefundenen ManagementObject-Objekten zurück. Über diese kann man mit dem Namen gewünschten Eigenschaft zugreifen.</li>
</ol>
<p>Hier ein Beispiel um den Namen, die ID und die MAC-Adresse aller Netzwerkkarten (virtuell oder nicht) in einer MessageBox anzeigen zu lassen:</p>
<div>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none"><span style="color: #0000ff;">string</span> query = <span style="color: #006080;">"SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID IS NOT null"</span>;
ManagementObjectSearcher sucher = <span style="color: #0000ff;">new</span> ManagementObjectSearcher(query);

<span style="color: #0000ff;">string</span> s = <span style="color: #006080;">""</span>;
<span style="color: #0000ff;">foreach</span> (ManagementObject m <span style="color: #0000ff;">in</span> sucher.Get())
{
    <span style="color: #008000;">// NetConnectionID Name der Karte wie in der Systemsteuerung</span>
    <span style="color: #008000;">// DeviceID ID HardwareID wie in der Registry</span>
    s += m[<span style="color: #006080;">"NetConnectionID"</span>] +
        <span style="color: #006080;">" ID "</span> + m[<span style="color: #006080;">"DeviceID"</span>] +
        <span style="color: #006080;">" MAC "</span> + m[<span style="color: #006080;">"MACAddress"</span>] + <span style="color: #006080;">"\n"</span>;
}

MessageBox.Show(s);</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://oliana.de/blog/2008/03/21/wmi-informationen-mit-c-auslesen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.574 seconds -->
