<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Winforms Development</title>
        <link>http://community.dotnetwork.it/Excentric/category/69.aspx</link>
        <description>Winforms Development</description>
        <language>en-US</language>
        <copyright>Sabrina C.</copyright>
        <managingEditor>ziayeye@ziayeye.it</managingEditor>
        <generator>Subtext Version 1.9.5.176</generator>
        <item>
            <title>Work with a simple HTTP Listener and avoid problems with BOM</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2011/10/09/work-with-a-simple-http-listener-and-avoid-problems-with.aspx</link>
            <description>&lt;p&gt;We are implementing an internal service (internal means that it runs on an intranet) for one of our softwares that exchanges messages with my application clients when they run on the users machines. The data exchanged is sent as an XML class to an HTTP Listener. &lt;/p&gt;  &lt;p&gt;It looked all simple and easy except that, when the XML class arrived to the Listener, the XML De-Serializer went nuts telling us the class was not correctly formatted.&lt;/p&gt;  &lt;p&gt;After some checks to verify if we did something wrong (I always start from the principle that the probability I make a mess is higher than the one that compiler or libraries from third parties are wrong) and not finding nothing in the serialization and deserialization routines, sniffing the data arriving in the request, we discovered that the serialized data got 3 bytes preceding the &amp;lt;?xml which starts every xml data, in Hexadecimal EB BB BF, we didn’t understand what it was, and after a moment thinking to what could be wrong in our code to produce such problem, we made a search through the internet and learn something important (as always you never stop learning things…) Anyway, we discovered these three characters are a BOM (Byte order Mark) that is automatically added by the system serializing in UTF-8 encoding. Notepad, Notepad++ and other text editors/readers ignore it so you never notice it’s existence, but it is there. The problem in my service was that when deserializing from a string the three characters were not discarded so the Deserialize method gave an error telling that it found bad characters at the beginning of the class.&lt;/p&gt;  &lt;p&gt;Is there a way to avoid the problem with BOM? Yes, it is one of the parameters of the &lt;font color="#00df38"&gt;&lt;strong&gt;XmlWriterSettings&lt;/strong&gt;&lt;/font&gt; &lt;/p&gt;  &lt;pre class="CSharpFormat"&gt;XmlWriterSettings xstt = &lt;span class="kwrd"&gt;new&lt;/span&gt; XmlWriterSettings();

xstt.Encoding = Encoding.UTF8 : &lt;span class="kwrd"&gt;new&lt;/span&gt; UTF8Encoding(&lt;span class="kwrd"&gt;false&lt;/span&gt;);
&lt;span class="kwrd"&gt;using&lt;/span&gt; (XmlWriter writer = XmlWriter.Create(stream, xstt))
{
   ...
}&lt;/pre&gt;

&lt;p&gt;Using this option to serialize the class avoids the BOM and the deserialization problems. &lt;/p&gt;

&lt;p&gt;Hoping to help someone else solving this problem faster &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-winkingsmile" alt="Occhiolino" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/Windows-Live-Writer/d833b34e42a0_BE20/wlEmoticon-winkingsmile_2.png" /&gt;&lt;/p&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/894.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2011/10/09/work-with-a-simple-http-listener-and-avoid-problems-with.aspx</guid>
            <pubDate>Sun, 09 Oct 2011 19:49:47 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/894.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2011/10/09/work-with-a-simple-http-listener-and-avoid-problems-with.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/894.aspx</wfw:commentRss>
        </item>
        <item>
            <title>The Phantom Password &amp;hellip;</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2011/10/05/the-phantom-password-hellip.aspx</link>
            <description>&lt;p&gt;Between yesterday afternoon and today’s noon, two of us lost 4 x 2 = 8 hours of worktime to find the cause of the problem in this post’s subject. A class used many times in our projects suddenly stopped working it’s usual way giving strange error messages.&lt;/p&gt;  &lt;p&gt;I’m testing some classes for a new application using a Test application, the classes are using a SQLServer database, since I need to test on multiple databases, I’ve put on a form a textbox with the connectionstring to be able to change it on the fly.&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;strong&gt;Data Source&lt;/strong&gt;&lt;/font&gt;=NomeServer;&lt;strong&gt;&lt;font color="#0000ff"&gt;Initial Catalog&lt;/font&gt;&lt;/strong&gt;=NomeDatabase;&lt;font color="#0000ff"&gt;&lt;strong&gt;Password&lt;/strong&gt;&lt;/font&gt;=LaPassword;&lt;strong&gt;&lt;font color="#0000ff"&gt;User ID&lt;/font&gt;&lt;/strong&gt;=LUtente;&lt;/p&gt;  &lt;p&gt;The connection string was set as the one above, of all  the tests I made, just one uses a &lt;strong&gt;DataProvider&lt;/strong&gt; class, which contains a &lt;strong&gt;Dataset&lt;/strong&gt;, with one &lt;strong&gt;DataTable&lt;/strong&gt;, served by a &lt;strong&gt;SqlDataAdapter&lt;/strong&gt;, 4 &lt;strong&gt;SqlCommand&lt;/strong&gt; and a &lt;strong&gt;SqlConnection&lt;/strong&gt;. This is the kind of classes we use for CRUD on all our tables and they work fine. Yesterday, an operation made of: &lt;strong&gt;Fill&lt;/strong&gt; (call &lt;em&gt;DataAdapter’s Fill&lt;/em&gt;), &lt;strong&gt;AddRow&lt;/strong&gt;, &lt;strong&gt;Update&lt;/strong&gt; (call to &lt;em&gt;DataAdapter’supdate&lt;/em&gt;) gave an error telling that the user had no Login Rights on SQL Server.&lt;/p&gt;  &lt;p&gt;After 3 hours debugging step by step,  we discovered that the &lt;strong&gt;DataAdapter&lt;/strong&gt;, after calling the &lt;strong&gt;Fill&lt;/strong&gt; cutted the password from the ConnectionString property of the &lt;strong&gt;SqlConnection&lt;/strong&gt; class automatically. Being a class used on daily bases on all our applications we started wondering how was it possible that all worked correctly until yesterday.     &lt;br /&gt;After another hour of tests on various things, we debugged step by step one of our applications and we found out that we were not totally nuts, the difference was that the connection strings (built by a standard helper in all our applications) were made like the following one:&lt;/p&gt;  &lt;p&gt;&lt;font color="#0000ff"&gt;&lt;strong&gt;Data Source&lt;/strong&gt;&lt;/font&gt;=NomeServer;&lt;font color="#0000ff"&gt;&lt;strong&gt;Initial Catalog&lt;/strong&gt;&lt;/font&gt;=NomeDatabase;&lt;font color="#0000ff"&gt;&lt;strong&gt;Password&lt;/strong&gt;&lt;/font&gt;=LaPassword;&lt;font color="#0000ff"&gt;&lt;strong&gt;User ID&lt;/strong&gt;&lt;/font&gt;=LUtente;&lt;strong&gt;&lt;font color="#0000ff"&gt;Persist Security Info&lt;/font&gt;&lt;/strong&gt;=true;&lt;/p&gt;  &lt;p&gt;So, if a  &lt;strong&gt;DataAdapter&lt;/strong&gt; after the first call to one of its commands, eats the password, this is why. If the Persist Security Info, which is by the way one of the Not recommended options, is not in the connectionstring, after the first Connection Open it is discarded automatically. On the documentation it is specified this is a logic thing made for security reasons. Anyway it is the kind of problem that makes you feel an idiot, asking yourself “How it is possible it never happened before?”&lt;/p&gt;  &lt;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:747ba95f-ee87-4126-baf0-38879fa8e063" class="wlWriterEditableSmartContent"&gt;Tag di Technorati: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SqlDataAdapter" rel="tag"&gt;SqlDataAdapter&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/892.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2011/10/05/the-phantom-password-hellip.aspx</guid>
            <pubDate>Wed, 05 Oct 2011 12:37:54 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/892.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2011/10/05/the-phantom-password-hellip.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/892.aspx</wfw:commentRss>
        </item>
        <item>
            <title>HTTP Listener and XML</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2011/08/10/http-listener-and-xml.aspx</link>
            <description>&lt;p&gt;Today, working at a small project using the .Net object in the title, we found something weird; if I used an HTTP Get to send a string to the Listener and the string was a plain text like “Hello, I am the string”, it arrived exactly as it was sent, while if the string was the XML serialization of a custom object the result string was different when received and before the &amp;lt;?xml we found three characters, an i with an umlaot, a closing double quote, and an upside down question mark.   &lt;br /&gt;Digging into the string we found that the XML Serialization by default inserts as first character of a serialized string/file the unicode character  &lt;strong&gt;\UFEFF&lt;/strong&gt;, which is a non visible character (also notepad does not show it), this character is necessary to the device/software/whatever that receives the text to determine if it is &lt;em&gt;BigEndian&lt;/em&gt; or &lt;em&gt;LittleEndian&lt;/em&gt;, You can find the details here on &lt;a href="http://en.wikipedia.org/wiki/byte_order_mark"&gt;Wikipedia&lt;/a&gt; if you are curious. This unicode character can be omitted in serialization just asking it to the .NET serializer, changing a property in the &lt;font color="#7cc80b"&gt;&lt;strong&gt;XmlWriterSettings&lt;/strong&gt;&lt;/font&gt; that you give to the &lt;font color="#04a5e1"&gt;&lt;strong&gt;XmlSerializer&lt;/strong&gt;&lt;/font&gt; the property is &lt;font color="#ff0000"&gt;&lt;strong&gt;Encoding&lt;/strong&gt;&lt;/font&gt;=&lt;font color="#0000ff"&gt;&lt;strong&gt;false&lt;/strong&gt;&lt;/font&gt; to exclude the character. &lt;/p&gt;  &lt;p&gt;It is not exactly a solution, but it is a good workaround if you cannot do more. The real solution is call an &lt;strong&gt;UrlEncoding&lt;/strong&gt; of the XML string before sending it using the GET, or else, if you want to be sure everything remains unchanged, you can convert the XML string to BASE64 Using Encoding.Unicode to obtain a Byte Array from the string and then parse it when received from the listener. &lt;/p&gt;  &lt;p&gt;Usually the exception you receive when this problem happens is the following:&lt;/p&gt;  &lt;pre&gt;System.Xml.XmlException
Data at the root level is invalid. Line 1, position 1.&lt;/pre&gt;

&lt;p&gt;here is the screenshot of the XML string with the problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/Windows-Live-Writer/HTTP-Listener-e-XML_C52C/xml_err_2.jpg" rel="lightbox"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="xml_err" border="0" alt="xml_err" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/Windows-Live-Writer/HTTP-Listener-e-XML_C52C/xml_err_thumb.jpg" width="386" height="112" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;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:89c86d07-6a30-48cb-bdf3-a73c7ec5c474" class="wlWriterEditableSmartContent"&gt;Tag di Technorati: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/HTTPListener" rel="tag"&gt;HTTPListener&lt;/a&gt;,&lt;a href="http://technorati.com/tags/XML" rel="tag"&gt;XML&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Encoding" rel="tag"&gt;Encoding&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/861.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2011/08/10/http-listener-and-xml.aspx</guid>
            <pubDate>Wed, 10 Aug 2011 14:48:00 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/861.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2011/08/10/http-listener-and-xml.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/861.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Capture screenshots from multiple screens in C#</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2011/01/17/capture-screenshots-from-multiple-screens-in-c.aspx</link>
            <description>&lt;p&gt;Today Stefano, a friend asked a question on our forum that looked very easy to answer.&lt;/p&gt;
&lt;p&gt;“I Use Screen.PrimaryScreen to capture the screen in C# but I have a multiple screen environment (4 screens) and I need to capture them all. Any Ideas?”&lt;/p&gt;
&lt;p&gt;The Answer was simple, Screen class has an AllScreens Property which is an array giving us all the screens connected to the PC, using that you can easily Capture Each screen image using a for cycle with the following code for each screen:&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;                Bitmap ps = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bitmap(x.Bounds.Width, x.Bounds.Height);

                Graphics graphics = Graphics.FromImage(ps &lt;span class="kwrd"&gt;as&lt;/span&gt; Image);
                graphics.CopyFromScreen(x.Bounds.X, x.Bounds.Y, 0, 0, x.Bounds.Size);

                ps.Save(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;@"c:\MultiImage{0}.jpg"&lt;/span&gt;, i), ImageFormat.Jpeg);

                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"DONE &amp;lt;{0}&amp;gt; "&lt;/span&gt;, i) + Environment.NewLine;&lt;/pre&gt;
&lt;p&gt;But what He really wanted was a single image containing the whole screen, the same thing you obtain using a printscreen. &lt;br /&gt;
And that’s not so simple.&lt;/p&gt;
&lt;p&gt;Infact, I made a test with 2 screens, using my notebook, and Windows Vista and 7 (I don’t remember if XP made the same), when you have multiple screens allows you to position the secondary screens on whatever side of your primary screen you desire, changing consequently the properties indicating where the secondary screen (or screens) are positioned based on the primary one.&lt;/p&gt;
&lt;p&gt;Because of this, composing an image is not so easy and requires some calculations, (of course you can use the clipboard if you prefer, but we are here to learn C# and use .NET right?).&lt;/p&gt;
&lt;p&gt;This is what I ended up with:&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;            &lt;span class="kwrd"&gt;int&lt;/span&gt; width = 0;
            &lt;span class="kwrd"&gt;int&lt;/span&gt; height = 0;
            &lt;span class="kwrd"&gt;int&lt;/span&gt; minx = 0;
            &lt;span class="kwrd"&gt;int&lt;/span&gt; miny = 0;
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Screen.AllScreens.Length; i++)
            {
                Screen z = Screen.AllScreens[i];
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (z.Bounds.X &amp;lt; minx) minx = z.Bounds.X;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (z.Bounds.Y &amp;lt; miny) miny = z.Bounds.Y;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (i == 0)
                {
                    width = z.Bounds.Width;
                    height = z.Bounds.Height;
                }
                &lt;span class="kwrd"&gt;else&lt;/span&gt;
                {
                    Screen p = Screen.AllScreens[i - 1];
                    &lt;span class="rem"&gt;//Sta a destra&lt;/span&gt;
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (z.Bounds.Right &amp;gt; p.Bounds.Right)
                    {
                        width += z.Bounds.Right - p.Bounds.Right;
                    }
                    &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    {
                        &lt;span class="rem"&gt;//sta a sinistra&lt;/span&gt;
                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (z.Bounds.Left &amp;lt; p.Bounds.Left)
                        {
                            width += Math.Abs(p.Bounds.Left - z.Bounds.Left);
                        }
                    }
                    &lt;span class="rem"&gt;//sta sopra&lt;/span&gt;
                    &lt;span class="kwrd"&gt;if&lt;/span&gt; (z.Bounds.Top &amp;lt; p.Bounds.Top)
                    {
                        height += (Math.Abs(z.Bounds.Top) - Math.Abs(z.Bounds.Bottom));
                    }
                    &lt;span class="kwrd"&gt;else&lt;/span&gt;
                    {
                        &lt;span class="kwrd"&gt;if&lt;/span&gt; (z.Bounds.Bottom &amp;gt; p.Bounds.Bottom)
                        {
                            height += z.Bounds.Bottom - p.Bounds.Bottom;
                        }
                    }

                }
            }&lt;/pre&gt;
&lt;p&gt;Based on the secondary screen position I’ve calculated the total image width and height and the offset of the bitmaps.&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;            Bitmap ps = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bitmap(width, height);
            Graphics graphics = Graphics.FromImage(ps &lt;span class="kwrd"&gt;as&lt;/span&gt; Image);

            &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text = &lt;span class="str"&gt;""&lt;/span&gt;;
            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; Screen.AllScreens.Length; i++)
            {
                Screen x = Screen.AllScreens[i];
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"-------------------&amp;gt;{0}&amp;lt;-------------------------"&lt;/span&gt;, i)&lt;br /&gt;                    + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Top:"&lt;/span&gt; + x.Bounds.Top.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Bottom:"&lt;/span&gt; + x.Bounds.Bottom.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Left:"&lt;/span&gt; + x.Bounds.Left.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Right:"&lt;/span&gt; + x.Bounds.Right.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"X:"&lt;/span&gt; + x.Bounds.X.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Y:"&lt;/span&gt; + x.Bounds.Y.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Width:"&lt;/span&gt; + x.Bounds.Width.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="str"&gt;"Height:"&lt;/span&gt; + x.Bounds.Height.ToString() + Environment.NewLine;
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"-------------------&amp;lt;{0}&amp;gt;-------------------------"&lt;/span&gt;,&lt;br /&gt;                     i) + Environment.NewLine;
                graphics.CopyFromScreen(x.Bounds.X, x.Bounds.Y, x.Bounds.X + (Math.Abs(minx)),&lt;br /&gt;                      x.Bounds.Y + Math.Abs(miny), x.Bounds.Size);

                ps.Save(&lt;span class="str"&gt;@"c:\SingleImage.jpg"&lt;/span&gt;, ImageFormat.Jpeg);
                &lt;span class="kwrd"&gt;this&lt;/span&gt;.textBox1.Text += &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"DONE &amp;lt;{0}&amp;gt; "&lt;/span&gt;, i) + Environment.NewLine;
            }&lt;/pre&gt;
&lt;p&gt;Then I compose the bitmap joining the two pieces of screen. I’m sure there is a better way of doing it, and of course &lt;br /&gt;
You probably need to change some things to make it work with three or more screens. &lt;br /&gt;
If you try it, let me know.&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;&lt;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:2ab1b8ee-a87d-4249-9e38-5be8ea8a5c93" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a rel="tag" href="http://technorati.com/tags/C%23"&gt;C#&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/capture+screen"&gt;capture screen&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;
&lt;/p&gt;&lt;div style="PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-LEFT: 0px; PADDING-RIGHT: 0px; DISPLAY: inline; FLOAT: none; PADDING-TOP: 0px" class="wlWriterEditableSmartContent"&gt;To download the code, Log in and go to &lt;a href="http://www.dotnetwork.it/Contenuti/Risorse/tabid/63/Default.aspx"&gt;resources area &lt;/a&gt;&lt;/div&gt;
&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/596.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2011/01/17/capture-screenshots-from-multiple-screens-in-c.aspx</guid>
            <pubDate>Mon, 17 Jan 2011 18:38:46 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/596.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2011/01/17/capture-screenshots-from-multiple-screens-in-c.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/596.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Using Date differences to build a countdown to new year</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/12/30/using-date-differences-to-build-a-countdown-to-new-year.aspx</link>
            <description>&lt;p&gt;A small application inspired by Stefano Pranzo, to create a countdown to new year.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;&lt;a rel="lightbox" href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/UsareledifferenzefraDateperuncountdowndi_9F36/frmcountdown_2.jpg"&gt;&lt;img style="BORDER-RIGHT-WIDTH: 0px; DISPLAY: inline; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" title="frmcountdown" border="0" alt="frmcountdown" width="546" height="356" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/UsareledifferenzefraDateperuncountdowndi_9F36/frmcountdown_thumb.jpg" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The final result is shown in the above image, to create it we have to create a new Windows Forms Application, rename its Form1 to FrmCountdown and change the following properties:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;BackgroundImage –&amp;gt;Choose an image from your disk using the 3 dots button and import it into the project resources. I’ve found the above one writing newyear on the bing image search. &lt;/li&gt;
    &lt;li&gt;BackgroundImageLayout –&amp;gt; Stretch &lt;/li&gt;
    &lt;li&gt;FormBorderStyle –&amp;gt; None &lt;/li&gt;
    &lt;li&gt;KeyPreview –&amp;gt; True (we will use it to manage quit application). &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We add a label to the form named lblCountdown with the following properties:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;BackColor –&amp;gt; transparent &lt;/li&gt;
    &lt;li&gt;Font Name –&amp;gt; Lucida Calligraphy &lt;/li&gt;
    &lt;li&gt;Font Size –&amp;gt; 64 &lt;/li&gt;
    &lt;li&gt;Forecolor –&amp;gt; Gold &lt;/li&gt;
    &lt;li&gt;TextAlign –&amp;gt; MiddleCenter &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We add a button to the form named btnClose with the following properties:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;UseVisualStyleBackColor –&amp;gt; False &lt;/li&gt;
    &lt;li&gt;FlatStyle –&amp;gt; Flat &lt;/li&gt;
    &lt;li&gt;BackColor –&amp;gt; transparent &lt;/li&gt;
    &lt;li&gt;Font Name –&amp;gt; Lucida Calligraphy &lt;/li&gt;
    &lt;li&gt;Forecolor –&amp;gt; Gold &lt;/li&gt;
    &lt;li&gt;Text –&amp;gt; Close &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We add to the form a timer named tmrCountdown.&lt;/p&gt;
&lt;p&gt;The code behind the form is the following:&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; FrmCountDown()
        {
            InitializeComponent();
            tmrCountdown.Interval = 1000;
            tmrCountdown.Enabled = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
        }&lt;/pre&gt;
&lt;p&gt;In the form constructor we set the timer to an interval of 1000 milliseconds.&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FrmCountDown_Load(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            tmrCountdown.Start();
        }&lt;/pre&gt;
&lt;p&gt;On the Load  event of the form we activate the timer.&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnClose_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            Application.Exit();
        }&lt;/pre&gt;
&lt;p&gt;On the click event of the Close button we implement the application exit.&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; FrmCountDown_KeyUp(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, KeyEventArgs e)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (e.KeyCode == Keys.Escape)
            {
                Application.Exit();
            }
        }&lt;/pre&gt;
&lt;p&gt;On the key Up event of the form we implement the application exit if  Esc key is pressed.&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;        DateTime mDtEnd = &lt;span class="kwrd"&gt;new&lt;/span&gt; DateTime(2011, 01, 01, 0, 0, 0);&lt;/pre&gt;
&lt;p&gt;We set a DateTime variable at form level with the final date and time, so 00:00:00 of january first.&lt;/p&gt;
&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; tmrCountdown_Tick(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            TimeSpan sp = mDtEnd.Subtract(DateTime.Now);
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.lblCountdown.Text = sp.TotalHours.ToString(&lt;span class="str"&gt;"###"&lt;/span&gt;) + &lt;span class="str"&gt;":"&lt;/span&gt; + &lt;br /&gt;                sp.Minutes.ToString(&lt;span class="str"&gt;"0#"&lt;/span&gt;) + &lt;span class="str"&gt;":"&lt;/span&gt; + sp.Seconds.ToString(&lt;span class="str"&gt;"0#"&lt;/span&gt;);
            Application.DoEvents();
        }&lt;/pre&gt;
&lt;p&gt;Finally on the Tick event of the timer we update  our label calculating a difference between present date and time and the final date and time, converting then the data in a formatted string. As you can see we use the Subtract method of the DateTime class and the properties TotalHours, Minutes and Seconds of the Timespan representing the difference between the two dates.&lt;/p&gt;
&lt;p&gt;Our NewYear Countdown is ready to go.&lt;br /&gt;
You can find the full project with working code in the resources area &lt;a href="http://www.dotnetwork.it/Contenuti/Risorse/tabid/63/Default.aspx"&gt;Cpde for Countdown&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Happy newyear Everybody!&lt;/p&gt;
&lt;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:9894c469-aad4-4f83-a5ce-df940bde63f9" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a rel="tag" href="http://technorati.com/tags/DateTime"&gt;DateTime&lt;/a&gt;,&lt;a rel="tag" href="http://technorati.com/tags/Winforms"&gt;Winforms&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/588.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/12/30/using-date-differences-to-build-a-countdown-to-new-year.aspx</guid>
            <pubDate>Thu, 30 Dec 2010 10:49:41 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/588.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/12/30/using-date-differences-to-build-a-countdown-to-new-year.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/588.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Access the Deleted Rows of a Datatable</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/08/09/access-the-deleted-rows-of-a-datatable.aspx</link>
            <description>&lt;p&gt;Today, I’m updating the Code Generator I’ve made in 2006 to build automatically the Data Provider classes for my applications. I’m passing my applications to Framework 4.0 and instead of a simple framework change, I’ve decided to make some cleaning in Old Common Libraries code and add some new features in the Data Classes.&lt;/p&gt;  &lt;p&gt;One of the new features in my data classes, will be some events, raised when data operations complete, RowAdded and RowDeleted events are two of them. In both cases, it would probably be useful if you Handle the Event in your code, to have some informations on the Added Row or Deleted Row, so I decided to pass the whole DataRow as a property of the event argument.&lt;/p&gt;  &lt;p&gt;Pass the Added row as an argument is very simple, I have the object in my method.&lt;/p&gt;  &lt;p&gt;Pass the Deleted row is a little less simple. I’ve made a simple test project to find out how to get it, to be precise, the exact phrase is: &lt;em&gt;How to get a copy of it&lt;/em&gt;.&lt;/p&gt;  &lt;p&gt;The sample form is the following:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/AccesstheDeletedRowsofaDatatable_EFEB/righecancellate_2.jpg" rel="lightbox"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="righecancellate" border="0" alt="righecancellate" src="http://community.dotnetwork.it/images/community_dotnetwork_it/Excentric/WindowsLiveWriter/AccesstheDeletedRowsofaDatatable_EFEB/righecancellate_thumb.jpg" width="244" height="184" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;On the form there are 3 buttons – Carica = Load, Test Aggiunta = Test AddRow, Test cancellazione = Test Deletion. There is also a textbox, set as Multiline with vertical scrollbar.&lt;/p&gt;  &lt;p&gt;The test code is the following:&lt;/p&gt;  &lt;pre class="CSharpFormat"&gt;        DataTable mDt;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FLD_ID = &lt;span class="str"&gt;"ID"&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FLD_Description = &lt;span class="str"&gt;"Description"&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FLD_Date = &lt;span class="str"&gt;"Date"&lt;/span&gt;;
        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;const&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; FLD_Price = &lt;span class="str"&gt;"Price"&lt;/span&gt;;

        &lt;span class="kwrd"&gt;public&lt;/span&gt; Form1()
        {
            InitializeComponent();
            mDt = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataTable(&lt;span class="str"&gt;"Tbtest"&lt;/span&gt;);
            DataColumn col = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataColumn(FLD_ID, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;int&lt;/span&gt;));
            col.AutoIncrement = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
            col.AutoIncrementSeed = 1;
            col.AutoIncrementStep = 1;
            mDt.Columns.Add(col);
            col = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataColumn(FLD_Description, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(&lt;span class="kwrd"&gt;string&lt;/span&gt;));
            mDt.Columns.Add(col);
            col = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataColumn(FLD_Date, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(DateTime));
            mDt.Columns.Add(col);
            col = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataColumn(FLD_Price, &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(Decimal));
            mDt.Columns.Add(col);
        }&lt;/pre&gt;

&lt;p&gt;The initialization code, I build a Datatable on the Constructor code of the form.&lt;/p&gt;

&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnCarica_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            mDt.Rows.Clear();

            DataRow row = mDt.NewRow();
            row[FLD_Description] = &lt;span class="str"&gt;"Quaderno"&lt;/span&gt;;
            row[FLD_Date] = DateTime.Now;
            row[FLD_Price] = 1.5;
            mDt.Rows.Add(row);

            row = mDt.NewRow();
            row[FLD_Description] = &lt;span class="str"&gt;"Penna"&lt;/span&gt;;
            row[FLD_Date] = DateTime.Now;
            row[FLD_Price] = 2.8;
            mDt.Rows.Add(row);

            row = mDt.NewRow();
            row[FLD_Description] = &lt;span class="str"&gt;"Gomma"&lt;/span&gt;;
            row[FLD_Date] = DateTime.Now;
            row[FLD_Price] = 0.7;
            mDt.Rows.Add(row);

            row = mDt.NewRow();
            row[FLD_Description] = &lt;span class="str"&gt;"Matita"&lt;/span&gt;;
            row[FLD_Date] = DateTime.Now;
            row[FLD_Price] = 1.1;
            mDt.Rows.Add(row);

            row = mDt.NewRow();
            row[FLD_Description] = &lt;span class="str"&gt;"Block notes"&lt;/span&gt;;
            row[FLD_Date] = DateTime.Now;
            row[FLD_Price] = 2.8;
            mDt.Rows.Add(row);

            row = mDt.NewRow();
            row[FLD_Description] = &lt;span class="str"&gt;"Pennarelli 12 colori"&lt;/span&gt;;
            row[FLD_Date] = DateTime.Now;
            row[FLD_Price] = 6.7;
            mDt.Rows.Add(row);

            mDt.AcceptChanges();

            Mostra();
        }&lt;/pre&gt;

&lt;p&gt;Here I build some rows, put them in the DataTable and call the Mostra method, wich shows the rows in the textbox.&lt;/p&gt;

&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Mostra()
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtResult.Text = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;
            &lt;span class="kwrd"&gt;for&lt;/span&gt;( &lt;span class="kwrd"&gt;int&lt;/span&gt; i=0; i&amp;lt; mDt.Rows.Count;i++)
            {
                MostraRiga(mDt.Rows[i]);
            }
    
        }

        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; MostraRiga(DataRow pRow)
        {
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtResult.Text += &lt;span class="str"&gt;"ID: "&lt;/span&gt; + pRow[FLD_ID].ToString() + Environment.NewLine;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtResult.Text += &lt;span class="str"&gt;"Description: "&lt;/span&gt; + pRow[FLD_Description].ToString() + Environment.NewLine;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtResult.Text += &lt;span class="str"&gt;"Date: "&lt;/span&gt; + pRow[FLD_Date].ToString() + Environment.NewLine;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtResult.Text += &lt;span class="str"&gt;"Price: "&lt;/span&gt; + pRow[FLD_Price].ToString() + Environment.NewLine;
            &lt;span class="kwrd"&gt;this&lt;/span&gt;.txtResult.Text += Environment.NewLine;
        }&lt;/pre&gt;

&lt;p&gt;This is the Mostra method and the MostraRiga Method, made to show the content of the table rows on the textbox.&lt;/p&gt;

&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnAdd_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {

            DataRow row = mDt.NewRow();
            mDt.Rows.Add(row);
            row[FLD_Description] = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"Nuova riga {0}"&lt;/span&gt;, row[FLD_ID]);
            row[FLD_Date] = DateTime.Now;
            &lt;span class="kwrd"&gt;decimal&lt;/span&gt; pippo = Convert.ToDecimal(row[FLD_ID]);
            row[FLD_Price] = pippo*0.98m;

            mDt.AcceptChanges();

            MostraRiga(row);
        }&lt;/pre&gt;

&lt;p&gt;Here is the AddRow test, that simply builds a row, adds it to the table and then shows it on the textbox.&lt;/p&gt;

&lt;pre class="CSharpFormat"&gt;        &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; btnDelete_Click(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
        {
            DataRow row = mDt.Rows[0];
            &lt;span class="kwrd"&gt;int&lt;/span&gt; id = Convert.ToInt32(row[FLD_ID]);
            row.Delete();
            &lt;span class="kwrd"&gt;string&lt;/span&gt; filter = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0} = {1}"&lt;/span&gt;, FLD_ID, id);
            DataView vi = &lt;span class="kwrd"&gt;new&lt;/span&gt; DataView(mDt, filter,&lt;span class="str"&gt;""&lt;/span&gt;, DataViewRowState.Deleted);
            DataTable tt = vi.ToTable();
            mDt.AcceptChanges();
            MostraRiga(tt.Rows[0]);
        }&lt;/pre&gt;

&lt;p&gt;And finally the most important bit of code, the code that helps us to show the informations of the deleted row.
  &lt;br /&gt;As you can see, the method simply deletes the first row of the DataTable, saving it’s ID. 

  &lt;br /&gt;After the deletion, to be able to get the whole row, I build a dataview that retrieves the row I’ve deleted and then uses the ToTable method of the DataView to put the data in a new Table. Then I give the Row to the MostraRiga (ShowRow) method and I can see its content on my textbox.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;&lt;font color="#ff0000"&gt;ToTable &lt;/font&gt;&lt;/strong&gt;passage is very important, because if you try to pass to the function something like:&lt;/p&gt;

&lt;pre class="CSharpFormat"&gt;MostraRiga(vi[0].Row);&lt;/pre&gt;

&lt;p&gt;Whichis perfectly legal with a non deleted row, you instead receive an Exception, because you cannot access deleted rows data.&lt;/p&gt;

&lt;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:17113bfd-eb5e-4299-8c45-1632c622454a" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/DataTable" rel="tag"&gt;DataTable&lt;/a&gt;,&lt;a href="http://technorati.com/tags/DataView" rel="tag"&gt;DataView&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Deleted+Rows" rel="tag"&gt;Deleted Rows&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/482.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/08/09/access-the-deleted-rows-of-a-datatable.aspx</guid>
            <pubDate>Mon, 09 Aug 2010 15:03:42 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/482.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/08/09/access-the-deleted-rows-of-a-datatable.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/482.aspx</wfw:commentRss>
        </item>
        <item>
            <title>How to determine which Control raised the Item Changed Event on a Currency Manager</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/07/27/how-to-determine-which-control-raised-the-item-changed-event.aspx</link>
            <description>&lt;p&gt;A simple and fast post on C#, as usual to glue the solution of a problem  in a place where I know I can find it in the future.&lt;/p&gt;  &lt;p&gt;The currency manager object is both loved and hated by those who usually ask questions in the forums where I use to answer, I found it useful, even though sometimes it seems a little bit tricky in its behaviours.&lt;/p&gt;  &lt;p&gt;The &lt;font color="#0080ff"&gt;&lt;strong&gt;ItemChanged&lt;/strong&gt;&lt;/font&gt; event, is raised by the Currency manager each time a bound control in the current context modifies the data bound to one of its properties. To determine which control has updated the data, in the &lt;strong&gt;ItemChangedEventArgs&lt;/strong&gt; we have an &lt;font color="#ff0000"&gt;&lt;strong&gt;Index&lt;/strong&gt;&lt;/font&gt; property. It is a 1 (one) based index, strange for the .Net, anyway, using this index in the &lt;strong&gt;Bindings&lt;/strong&gt; collection of the currency manager, we are able to find out which control modified the data. In the sample code below, if a particular textbox has modified the data, we Update the data on the Database using a Data provider Class.&lt;/p&gt;  &lt;pre class="CSharpFormat"&gt;
 &lt;span class="kwrd"&gt;void&lt;/span&gt; mCurMgr_ItemChanged(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, ItemChangedEventArgs e)
        {
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (mCurMgr.Bindings[e.Index - 1].Control.Name == txtPercentualeCons.Name)
                {
                    mDpScenariAziende.Update();
                }
        }&lt;/pre&gt;

&lt;p&gt; &lt;/p&gt;

&lt;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:69de7b2b-b946-4844-b538-4756d39a32fe" class="wlWriterEditableSmartContent"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/Winforms" rel="tag"&gt;Winforms&lt;/a&gt;,&lt;a href="http://technorati.com/tags/CurrencyManager" rel="tag"&gt;CurrencyManager&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/472.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/07/27/how-to-determine-which-control-raised-the-item-changed-event.aspx</guid>
            <pubDate>Tue, 27 Jul 2010 09:09:59 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/472.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/07/27/how-to-determine-which-control-raised-the-item-changed-event.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/472.aspx</wfw:commentRss>
        </item>
        <item>
            <title>This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2010/06/18/this-assembly-is-built-by-a-runtime-newer-than-the.aspx</link>
            <description>&lt;p&gt;This error is given by the gacutil.exe if you try to register in GAC an assembly built with Framework 4.0 and you are using the gacutil.exe built for Framework 2.0.&lt;/p&gt;  &lt;p&gt;The programs I develop don’t register any assembly in GAC when installed on an end user machine, except if there is the need to expose .Net function to a .COM application. &lt;/p&gt;  &lt;p&gt;On the development machines instead, all the general purpouse libraries of my organization are installed in GAC, this is made to avoid versioning problems in projects that are using more than one solution, and are modified in different moments of the developer working time.&lt;/p&gt;  &lt;p&gt;To register the libraries in GAC we use the gacutil.exe from a Post Build Event, the gacutil.exe has been conveniently copied in c:\windows to have it in the standard “PATH” environment variable.&lt;/p&gt;  &lt;p&gt;Trying to register in GAC an assembly produced with framework 4.0 I’ve received the message put in the title and my assembly was not registered in the GAC.&lt;/p&gt;  &lt;p&gt;The problem is due to the fact that the gacutil.exe I’m using was the version built for framework 2.0, which works correctly until framework 3.5. (since 2005). After some searches on the internet, where it is told that the utility ships with Visual Studio, I made a &lt;strong&gt;&lt;font color="#008000"&gt;dir /s&lt;/font&gt;&lt;/strong&gt; on my c:\ drive and found the new release of the utility here:&lt;/p&gt;  &lt;p&gt;C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools&lt;/p&gt;  &lt;p&gt;Copying the new utility and replacing the old one, my assemblies made with framework 4.0 are correctly registered in GAC. However, there is something different from before, the folder where the GAC was until framework 3.5,&lt;/p&gt;  &lt;p&gt;c:\Windows\Assembly&lt;/p&gt;  &lt;p&gt;is now replaced by:&lt;/p&gt;  &lt;p&gt;C:\Windows\Microsoft.NET\assembly\GAC_MSIL&lt;/p&gt;  &lt;p&gt;This is completely transparent for us Users, but probably it is the reason of the gacutil.exe upgrade we need to do.   &lt;br /&gt;The new version registers correctly the dlls made with older frameworks too.&lt;/p&gt;  &lt;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:0b541a59-5c49-4ee5-ae77-f1f95e53fb1d" class="wlWriterEditableSmartContent"&gt;Tags: &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/GAC/default.aspx" rel="tag"&gt;GAC&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/gacutil/default.aspx" rel="tag"&gt;gacutil&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/VS2010/default.aspx" rel="tag"&gt;VS2010&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/440.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2010/06/18/this-assembly-is-built-by-a-runtime-newer-than-the.aspx</guid>
            <pubDate>Fri, 18 Jun 2010 13:19:48 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/440.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2010/06/18/this-assembly-is-built-by-a-runtime-newer-than-the.aspx#feedback</comments>
            <slash:comments>15</slash:comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/440.aspx</wfw:commentRss>
        </item>
        <item>
            <title>A snippet to send an e-mail through a SMTP Server</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2009/12/30/a-snippet-to-send-an-e-mail-through-a-smtp-server.aspx</link>
            <description>&lt;p&gt;Today I ‘ve been developing a small application that, among other things, has the job to notify to some users the arrival of data from an ftp server.&lt;/p&gt;  &lt;p&gt;The application watches the ftp folder directly using a file system watcher and when a File is received, puts it in the right place and it notifies the users of the arrival of the new data.&lt;/p&gt;  &lt;p&gt;The notification is sent by an e-mail. Sending an e-mail using .NET  is very simple, but searching a snippet on the web I was not able to find a “simple sample” so I’ve written it here, just in case someone else needs it:&lt;/p&gt;  &lt;pre class="CSharpFormat"&gt;              &lt;span class="rem"&gt;//Send mail method&lt;/span&gt;
              &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Send( &lt;span class="kwrd"&gt;string&lt;/span&gt; pUser, &lt;span class="kwrd"&gt;string&lt;/span&gt; pPassword )
              {
                &lt;span class="rem"&gt;//Set the from, sender, replyto address&lt;/span&gt;
                MailAddress from = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(&lt;span class="str"&gt;"noreply@mydomain.com"&lt;/span&gt;);
                &lt;span class="rem"&gt;//Set the to address, if you have more recipients you can add them all&lt;/span&gt;
                &lt;span class="rem"&gt;//to the To, CC or BCC collections of MailMessage&lt;/span&gt;
                MailAddress to = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(&lt;span class="str"&gt;"recipientuser@hisdomain.com"&lt;/span&gt;);
                &lt;span class="rem"&gt;//Create the message&lt;/span&gt;
                MailMessage msg = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailMessage();
                /&lt;span class="rem"&gt;/Set from, sender and reply addresses&lt;/span&gt;
                msg.From = from;
                msg.Sender = from;
                msg.ReplyTo = from;
                &lt;span class="rem"&gt;//set the to address&lt;/span&gt;
                msg.To.Add(to);
                &lt;span class="rem"&gt;//set the subject&lt;/span&gt;
                msg.Subject = &lt;span class="str"&gt;"Subject of my message"&lt;/span&gt;;
                &lt;span class="rem"&gt;//set the priority&lt;/span&gt;
                msg.Priority =  MailPriority.Normal;
                &lt;span class="rem"&gt;//Indicate if it is an html or text message&lt;/span&gt;
                msg.IsBodyHtml = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                &lt;span class="rem"&gt;//Set the message body&lt;/span&gt;
                msg.Body = &lt;span class="str"&gt;"Simple text message body"&lt;/span&gt;;
                &lt;span class="rem"&gt;//Add a sample attachment&lt;/span&gt;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (File.Exists(&lt;span class="str"&gt;"c:\\myattachment.xml"&lt;/span&gt;)
                {
                    msg.Attachments.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; Attachment(&lt;span class="str"&gt;"c:\\myattachment.xml"&lt;/span&gt;));
                }
                &lt;span class="rem"&gt;//Generate the smtp client indicating the server address&lt;/span&gt;
                SmtpClient smtp = &lt;span class="kwrd"&gt;new&lt;/span&gt; SmtpClient(&lt;span class="str"&gt;"mail.mydomain.local"&lt;/span&gt;);
                &lt;span class="rem"&gt;//Set the method of delivery&lt;/span&gt;
                smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
                &lt;span class="rem"&gt;//You can set also the Port if you need it&lt;/span&gt;
                                
                &lt;span class="rem"&gt;//If the server requires credentials, you can set them here&lt;/span&gt;
                &lt;span class="kwrd"&gt;if&lt;/span&gt; (pUser != &lt;span class="kwrd"&gt;null&lt;/span&gt; &amp;amp;&amp;amp; pUser.Trim().Length &amp;gt; 0)
                {
                    smtp.UseDefaultCredentials = &lt;span class="kwrd"&gt;false&lt;/span&gt;;
                    smtp.Credentials = &lt;span class="kwrd"&gt;new&lt;/span&gt; NetworkCredential(pUser, pPassword);
                }
                &lt;span class="rem"&gt;//And now Send the message&lt;/span&gt;
                smtp.Send(msg);
               }    &lt;/pre&gt;

&lt;p&gt;If you need to send an HTML message, just change these two rows:&lt;/p&gt;

&lt;pre class="CSharpFormat"&gt;                &lt;span class="rem"&gt;//Indicate if it is an html or text message&lt;/span&gt;
                msg.IsBodyHtml = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
                &lt;span class="rem"&gt;//Set the message body&lt;/span&gt;
                msg.Body = &lt;span class="str"&gt;"&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;p&amp;gt;Simple HTML message body.&amp;lt;/p&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;;&lt;/pre&gt;

&lt;div class="wlWriterEditableSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:1d8f49da-6355-407a-96a4-d82816903744" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px"&gt;Technorati Tag: &lt;a href="http://technorati.com/tags/C%23" rel="tag"&gt;C#&lt;/a&gt;,&lt;a href="http://technorati.com/tags/E-mail" rel="tag"&gt;E-mail&lt;/a&gt;,&lt;a href="http://technorati.com/tags/SMTP" rel="tag"&gt;SMTP&lt;/a&gt;&lt;/div&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/281.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2009/12/30/a-snippet-to-send-an-e-mail-through-a-smtp-server.aspx</guid>
            <pubDate>Wed, 30 Dec 2009 17:55:17 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/281.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2009/12/30/a-snippet-to-send-an-e-mail-through-a-smtp-server.aspx#feedback</comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/281.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Shortcut generated by Setup of Visual Studio and ORCA</title>
            <link>http://community.dotnetwork.it/Excentric/archive/2009/12/27/shortcut-generated-by-setup-of-visual-studio-and-orca.aspx</link>
            <description>&lt;p&gt;Sometimes the names chosen by Microsoft developers for applications make me think they are natives from my neighborhoods, in fact “orca miseria” is one of the favourite curses here where I live :D:D:D. In this case however the object named this way is very useful to avoid cursing. &lt;/p&gt;  &lt;p&gt;ORCA has nothing to do with ORCAS, It is an editor made to look and edit what is inside a compiled msi file and it is part of the Windows Installer SDK.&lt;/p&gt;  &lt;p&gt;I’ve discovered its existence by chance, searching a solution to an annoying problem, how to generate a shortcut in the SendTo folder of the user installing an application or the All Users SendTo folder. It is not possible using the Visual Studio .NET setup projects, because this kind of projects are able to generate only Advertised Shortcuts, these shortcuts got a different structure from the ones usually generated using the Right Key of the mouse both in XP and Vista (and I hope also in Windows Seven). It is a known problem since Visual Studio 2003 and part of a wish list since then, but it is not said the wish will ever come true.&lt;/p&gt;  &lt;p&gt;Of course there is a workaround given by ORCA; After you generate an msi setup file, if you want it to generate NON Advertised shortcuts, we can achieve this opening the msi file with ORCA (&lt;a href="http://www.technipages.com/download-orca-msi-editor.html" target="_blank"&gt;I’ve found it here&lt;/a&gt;). Go to Property using the Left side List, right click the Right window and add a property as follows:&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Name: DISABLEADVTSHORTCUTS&lt;/strong&gt;  Value: &lt;strong&gt;1&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;This way, the shortcuts are generated with the normal format, of course, this operation has to be done every time you rebuild the msi, which is a little bit annoying but very simple.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Tags: &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/msi/default.aspx" rel="tag"&gt;msi&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/installer/default.aspx" rel="tag"&gt;Installer&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/orca/default.aspx" rel="tag"&gt;Orca&lt;/a&gt;, &lt;a href="http://community.dotnetwork.it/Sabrina/Tags/setup/default.aspx" rel="tag"&gt;Setup&lt;/a&gt;&lt;/p&gt;&lt;img src="http://community.dotnetwork.it/Excentric/aggbug/279.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Sabrina C.</dc:creator>
            <guid>http://community.dotnetwork.it/Excentric/archive/2009/12/27/shortcut-generated-by-setup-of-visual-studio-and-orca.aspx</guid>
            <pubDate>Sun, 27 Dec 2009 20:00:49 GMT</pubDate>
            <wfw:comment>http://community.dotnetwork.it/Excentric/comments/279.aspx</wfw:comment>
            <comments>http://community.dotnetwork.it/Excentric/archive/2009/12/27/shortcut-generated-by-setup-of-visual-studio-and-orca.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://community.dotnetwork.it/Excentric/comments/commentRss/279.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>
