<?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>SOCARs TechBlog</title>
	<atom:link href="http://itblog.socar.pl/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://itblog.socar.pl</link>
	<description>Informatics tips &#38; tricks</description>
	<lastBuildDate>Tue, 22 Jun 2010 20:47:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>[JS] CKEditor problem under Opera fix</title>
		<link>http://itblog.socar.pl/?p=144</link>
		<comments>http://itblog.socar.pl/?p=144#comments</comments>
		<pubDate>Tue, 22 Jun 2010 20:46:40 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[dragonfly]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[opera]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[www]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=144</guid>
		<description><![CDATA[Problem: CKEditor 3.0 is a substitute to well known TinyMCE JavaScript editor. It&#8217;s easier to install and manage. It displays correctly under Chrome, Firefox or IE, but under latest Opera 10.xx CKEditor windows is not displayed correct. It doesn&#8217;t show at all. Some experienced users know that Opera has it&#8217;s own, very advanced, web-debugging mechanism [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:<br />
</strong>CKEditor 3.0 is a substitute to well known TinyMCE JavaScript editor. It&#8217;s easier to install and manage. It displays correctly under Chrome, Firefox or IE, but under latest Opera 10.xx CKEditor windows is not displayed correct. It doesn&#8217;t show at all. Some experienced users know that Opera has it&#8217;s own, very advanced, web-debugging mechanism &#8211; Dragonfly, which I&#8217;ve used to diagnose the &#8222;problem&#8221;.</p>
<p><strong>Solution:<br />
</strong>My CKEditor edit window appeared when I copied <em>config.js </em> file, from <em>./_source/core </em>to <em>./</em> path. Path desribed as ./ is path where <em>ckeditor.js</em> file is placed. That fixed the issue and CKEditor appears normally now under Opera 10.xx</p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=144</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[PHP] Hotlinking solution for CodeIgniter</title>
		<link>http://itblog.socar.pl/?p=138</link>
		<comments>http://itblog.socar.pl/?p=138#comments</comments>
		<pubDate>Fri, 07 May 2010 23:40:48 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[Bez kategorii]]></category>
		<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[hotlinking]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=138</guid>
		<description><![CDATA[I was having lately small problem with ImageSnip.com which I have developed few months ago. Site got some serious popularity in Asia and the images transfer was killing me. As we know, Asia i really big and very populated continent, so It would explain that few images fetched 200.000 times a day, where generating 5GB [...]]]></description>
			<content:encoded><![CDATA[<p>I was having lately small problem with <a href="http://www.imagesnip.com" target="_blank">ImageSnip.com</a> which I have developed few months ago. Site got some serious popularity in Asia and the images transfer was killing me. As we know, Asia i really big and very populated continent, so It would explain that few images fetched 200.000 times a day, where generating 5GB of traffic daily.</p>
<p>Although the traffic rate is high, most of the images were linked directly to server resources (images hotlinking). Hotlinked images ate my all free bandwidth in 4 days (20GB!) and I need to find a solution to that &#8230;</p>
<p>Solution to avoid hotlinking images is to place in images folder a .htaccess file. Although there are toms of examples, most of them don&#8217;t work for CodeIgniter framework (as ImageSnip is developed in), especially when developer uses &#8222;static&#8221; folder to host the css,js,images content&#8230;</p>
<p>After hour of browsing I&#8217;ve found solution(s) at <strong>Jeff Starr blog </strong>located at: <a href="http://perishablepress.com/press/2007/11/21/creating-the-ultimate-htaccess-anti-hotlinking-strategy/">http://perishablepress.com/press/2007/11/21/creating-the-ultimate-htaccess-anti-hotlinking-strategy/</a> which AT LAST WORKS! Code below:</p>
<pre class="brush: php;">
###############################
# ultimate hotlink protection #
###############################

# disable directory browsing
# uncomment this option to protect access to directories
# Options -Indexes

# enable the following of symlinks
# uncomment this option if hotlink protection fails to work
# Options +FollowSymLinks

# verify presence of mod rewrite
&lt;IfModule mod_rewrite.c&gt;

 # enable the rewrite engine
 RewriteEngine on

 # check that file exists
 RewriteCond %{REQUEST_FILENAME} -f

 # check for requested file types
 # include additional file types here
 RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$                [NC]

 # allow blank referrer requests
 RewriteCond %{HTTP_REFERER}     !^$

 # allow all requests from your domain
 # edit the domain to match your own
 RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain\.      [NC]

 # allow all requests from your ip address
 # edit the ip address to match your own
 RewriteCond %{HTTP_REFERER}     !^https?://123\.123\.123\.123(.*)$ [NC]

 # additional site access
 # include additional sites here replace domain names and or
 # remove unnecessary lines or add new lines for more sites
 RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain_01\.   [NC]
 RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain_02\.   [NC]
 RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain_03\.   [NC]

 # search engine access
 # include or remove search engines feed readers and other sites
 RewriteCond %{HTTP_REFERER}     !search\?q=cache                   [NC]
 RewriteCond %{HTTP_REFERER}     !google\.                          [NC]
 RewriteCond %{HTTP_REFERER}     !yahoo\.                           [NC]

 # allow access to all requests for your anti hotlink image
 # to serve an image instead of delivering a 403 error
 # uncomment the next line and edit the path and file name
 # RewriteCond %{REQUEST_URI}    !^/hotlink\.jpg$                   [NC]

 # deliver the hotlink image for all requests for the listed files
 # protect additional file types by editing the list below
 # if you are serving a file instead of a 403
 # uncomment the next line and edit the path and file name
 # RewriteRule \.(gif|jpe?g?|png)$ http://domain.tld/hotlink.jpg    [R,NC,L]

 # return a 403 error when any of the following file types is requested
 # you can protect additional file types by editing the list below
 RewriteRule \.(gif|jpe?g?|png)$                                  - [F,NC,L]

# close the module container
&lt;/ifModule&gt;
</pre>
<p>As Iam no expert in <em>.htaccess</em> file configuration, this one takes the cake!</p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=138</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#] Row select on right click (context menu)</title>
		<link>http://itblog.socar.pl/?p=135</link>
		<comments>http://itblog.socar.pl/?p=135#comments</comments>
		<pubDate>Thu, 01 Apr 2010 13:22:44 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[Bez kategorii]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=135</guid>
		<description><![CDATA[When using DataGridView control, activating it&#8217;s context menu (by right click on the grid) will not select the row/cell you are clicking at. For most of the operations users right-clicking on the grid want to perform operation on that selected item. Solution to this problem is to select item at same time as the Context [...]]]></description>
			<content:encoded><![CDATA[<p>When using DataGridView control, activating it&#8217;s context menu (by right click on the grid) will not select the row/cell you are clicking at. For most of the operations users right-clicking on the grid want to perform operation on that selected item.</p>
<p>Solution to this problem is to select item at same time as the Context menu is shown by using <strong>Opening<em> </em><span style="font-weight: normal;">event of the context menu. Following code should be pasted into the Opening event handler function:</span></strong></p>
<p><strong><span style="font-weight: normal;"> </span></strong></p>
<p><strong> </strong></p>
<pre class="brush: csharp;">

Point p = _myGRID.PointToClient(Cursor.Position);
DataGridView.HitTestInfo hti = _myGRID.HitTest(p.X, p.Y);
if (hti.RowIndex &gt; -1)
{
_grid_Feeds.ClearSelection();
_grid_Feeds.Rows[hti.RowIndex].Selected = true;
}
</pre>
<p>The right clicked row will be selected and from now on you can get the bound object by <strong><em>_myGRID.SelectedRow</em> </strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=135</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[PHP] Undefined index: lastBuildDate error fix</title>
		<link>http://itblog.socar.pl/?p=126</link>
		<comments>http://itblog.socar.pl/?p=126#comments</comments>
		<pubDate>Thu, 25 Mar 2010 20:35:05 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[Bez kategorii]]></category>
		<category><![CDATA[lastrss]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[rss]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=126</guid>
		<description><![CDATA[While working with lastRSS PHP lib I stumbed upon a following error: Undefined index: lastBuildDate / lastrss.php / Line Number: 160 As far as I googled around I didn&#8217;t find ONE precise fix for it, so I tinker with it and eventually It worked. Probably it&#8217;s solution for similar problems in other libs&#8230; Fix: In [...]]]></description>
			<content:encoded><![CDATA[<p>While working with lastRSS PHP lib I stumbed upon a following error:</p>
<p><strong><em>Undefined index: lastBuildDate / lastrss.php / Line Number: 160</em></strong></p>
<p>As far as I googled around I didn&#8217;t find ONE precise fix for it, so I tinker with it and eventually It worked. Probably it&#8217;s solution for similar problems in other libs&#8230;</p>
<p>Fix:</p>
<p>In lastrss.php find (around line 160)</p>
<pre class="brush: php;">
if ($this-&gt;date_format != '' &amp;&amp; ($timestamp = strtotime($result['lastBuildDate'])) !==-1) {
// convert lastBuildDate to specified date format
$result['lastBuildDate'] = date($this-&gt;date_format, $timestamp);
}
</pre>
<p>Trick is that PHP5 does not allow (or does not allow us to ignore that) access indexes in arrays that are not declared (or something&#8230;). This is PHP5 specific. Anyway fix for this is pretty simple, all what we need to do is to check if such result is defined whith <em>isset()</em> function. Correct code should look like this:</p>
<pre class="brush: php;">

if (isset($result['lastBuildDate']) &amp;&amp; $this-&gt;date_format != '' &amp;&amp; ($timestamp = strtotime($result['lastBuildDate'])) !==-1) {

// convert lastBuildDate to specified date format

$result['lastBuildDate'] = date($this-&gt;date_format, $timestamp);

}
</pre>
<p>In lastRSS lib (which is cool RSS parsing library for PHP) this occurs when two things get together:</p>
<ol>
<li>You define own date_format (and don&#8217;t leave it empty as default)</li>
<li>You fetch RSS for the first time (before the cache is written). Any another attempt on fetching feeds from same rss address will not cause this error to appear, as long as the cache will be read. If you clear the cache error will come again&#8230;</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=126</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Web] Can&#8217;t login to Live.com mail</title>
		<link>http://itblog.socar.pl/?p=124</link>
		<comments>http://itblog.socar.pl/?p=124#comments</comments>
		<pubDate>Mon, 22 Mar 2010 11:17:12 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[Bez kategorii]]></category>
		<category><![CDATA[live.com]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=124</guid>
		<description><![CDATA[I&#8217;am not a big fan of web based mail clients. I use them when I don&#8217;t have access to my primary systems (for ex. in cafes/PDA) but on my computers I&#8217;ve got installed standard stand-alone app mail client similar to Outlook (The Bat). I&#8217;ve recently created a mail account at live.com (Microsoft hosted mail system). [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;am not a big fan of web based mail clients. I use them when I don&#8217;t have access to my primary systems (for ex. in cafes/PDA) but on my computers I&#8217;ve got installed standard stand-alone app mail client similar to Outlook (The Bat). I&#8217;ve recently created a mail account at live.com (Microsoft hosted mail system). Logging thru web mail does not make any problems. Although setting the account in TheBat was a problem. When I configured everything I get error:</p>
<p><strong><em>-ERR authentication failed</em></strong></p>
<p>I was sure that provided config (server, ports, user name) was correct. After several attempts I found out that live.com services REQUIRES max 16 symbol passwords and my password was longer &#8230;</p>
<p>Shorting password length to 16 symbols does the trick and allows user (user@live.com) to login &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=124</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#] Easy solution for AutoScroll in GridView</title>
		<link>http://itblog.socar.pl/?p=111</link>
		<comments>http://itblog.socar.pl/?p=111#comments</comments>
		<pubDate>Sun, 03 Jan 2010 17:51:32 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[autoscroll]]></category>
		<category><![CDATA[gridview]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=111</guid>
		<description><![CDATA[Poking around standard WinForms GridView control I found it have not any &#8222;Autoscroll&#8221; properties. A proper approach would be create new control inherited from base GridView with altered component drawing and focusing etc, but I didn&#8217;t have time and will to do this, especially for my extremally simple FileSorter tool. So I came up with [...]]]></description>
			<content:encoded><![CDATA[<p>Poking around standard WinForms GridView control I found it have not any &#8222;Autoscroll&#8221; properties. A proper approach would be create new control inherited from base GridView with altered component drawing and focusing etc, but I didn&#8217;t have time and will to do this, especially for my extremally simple <a href="http://socar.pl/index.php?option=com_content&amp;view=article&amp;id=46&amp;Itemid=35" target="_blank">FileSorter</a> tool. So I came up with easy solution.</p>
<p><strong>The Problem:<br />
<span style="font-weight: normal;">Application have a grid, which is in real time adding new rows. When it&#8217;s view area height is reached, more rows are showed hidden &#8222;below&#8221; the view area of grid, and user is forced to use vertical scroll bar to scroll to them.</span></strong></p>
<p><strong>Solution:<br />
<span style="font-weight: normal;">We can use &#8222;FirstDisplayCell&#8221; property of DataGridView property</span></strong></p>
<p><strong>Code:<br />
<span style="font-weight: normal;"> </span></strong></p>
<p><strong> </strong></p>
<pre class="brush: csharp;">
if(_grid.Rows.Count&gt;0 &amp;&amp; _grid.Rows[_grid.Rows.Count-1].Cells.Count&gt;0)
   _grid.FirstDisplayedCell = _grid.Rows[_grid.Rows.Count-1].Cells[0];
</pre>
<p>Solution in 2 lines of code <img src='http://itblog.socar.pl/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p><strong> </strong></p>
<p><strong>Additional Notes:</strong></p>
<p>Method is thread safe and updates GUI properly using <em>Invoke</em> while invoking on a <em>_grid</em> object <strong> </strong></p>
<p><strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=111</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#] How to play simple system sound ?</title>
		<link>http://itblog.socar.pl/?p=108</link>
		<comments>http://itblog.socar.pl/?p=108#comments</comments>
		<pubDate>Sun, 13 Dec 2009 16:55:25 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=108</guid>
		<description><![CDATA[Its pretty simple to play system sounds, for example at the end of some operation: using System.Media; //.... SystemSounds.Asterisk.Play(); //Makes standard &#34;warning&#34; ding]]></description>
			<content:encoded><![CDATA[<p>Its pretty simple to play system sounds, for example at the end of some operation:</p>
<pre class="brush: csharp;">

using System.Media;

//....

SystemSounds.Asterisk.Play(); //Makes standard &quot;warning&quot; ding
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=108</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[.NET] Showing menu on button click</title>
		<link>http://itblog.socar.pl/?p=105</link>
		<comments>http://itblog.socar.pl/?p=105#comments</comments>
		<pubDate>Thu, 05 Nov 2009 10:29:08 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[winforms]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=105</guid>
		<description><![CDATA[This extremally easy thing, sometimes makes so much problem for someone who don&#8217;t know how to use .NET build in functions. As I saw, similar problem implementation in six lines of code (with pretty much calculations) it&#8217;s can be easily achived in one line. Problem: we want to show menu, on center of a button, [...]]]></description>
			<content:encoded><![CDATA[<p>This extremally easy thing, sometimes makes so much problem for someone who don&#8217;t know how to use .NET build in functions. As I saw, similar problem implementation in six lines of code (with pretty much calculations) it&#8217;s can be easily achived in one line.</p>
<p><strong>Problem:</strong> we want to show menu, on center of a button, which was clicked.<br />
<strong>Graphic representation:<br />
</strong><img class="aligncenter size-full wp-image-106" title="scroll_menu" src="http://itblog.socar.pl/wp-content/uploads/2009/11/scroll_menu.jpg" alt="scroll_menu" width="315" height="195" /></p>
<p><strong>Solution:</strong></p>
<pre class="brush: csharp;">

_context_menu.Show(_button_myButton, new Point(_button_myButton.Width/2, _button_myButton.Height/2));
</pre>
<p><strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=105</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[.NET] Relative path</title>
		<link>http://itblog.socar.pl/?p=98</link>
		<comments>http://itblog.socar.pl/?p=98#comments</comments>
		<pubDate>Wed, 04 Nov 2009 12:53:20 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=98</guid>
		<description><![CDATA[Below is a quick and dirty implementation of solution for how to get relative path to file from a folder Problem1: Path1 (base): C:\data\my_path Path2 (target): C:\some_other\folder\data\file.txt Result: ..\..\some_other\folder\data\file.txt Problem2: Path1 (base): C:\data\path Path2 (target): C:\data\path\somedata\file.txt Result: .\somedata\file.txt Solution: public static string getRelativePath(String baseDirectory, string destinationFile) { List&#60;String&#62; _from = new List&#60;String&#62;(baseDirectory.Split('\\')); List&#60;String&#62; _dest = [...]]]></description>
			<content:encoded><![CDATA[<p>Below is a quick and dirty implementation of solution for how to get relative path to file from a folder</p>
<p>Problem1:</p>
<p><strong>Path1 (base): </strong>C:\data\my_path<br />
<strong>Path2 (target): </strong>C:\some_other\folder\data\file.txt<br />
<strong>Result: ..\..\</strong>some_other\folder\data\file.txt</p>
<p>Problem2:<br />
<strong>Path1 (base): </strong>C:\data\path<br />
<strong>Path2 (target): </strong>C:\data\path\somedata\file.txt<br />
<strong>Result: </strong>.\somedata\file.txt</p>
<p><span style="text-decoration: underline;"><strong>Solution:</strong></span></p>
<pre class="brush: csharp;">
public static string getRelativePath(String baseDirectory, string destinationFile)
 {
   List&lt;String&gt; _from = new List&lt;String&gt;(baseDirectory.Split('\\'));
   List&lt;String&gt; _dest = new List&lt;String&gt;(destinationFile.Split('\\'));

   if (_from[0].ToLower() != _dest[0].ToLower() || _dest.Count==0 || _from.Count==0)
   {
     return destinationFile; //Not same disk
   }

   int lvl = 0;

   for(int i=0; i&lt;_from.Count; i++)
   {

    if (_from[i].ToLower() != _dest[i].ToLower())
    {
     break;
    }

    lvl++;
   }

   for (int j = 0; j &lt; lvl; j++)
   {
    _from.RemoveAt(0);
    _dest.RemoveAt(0);
   }

   String _resultPath = &quot;&quot;;
   if (_from.Count == 0) //the file is in higher folder
   {
    _resultPath += &quot;.\\&quot;;
    for (int i = 0; i &lt; _dest.Count; i++)
    {
     _resultPath += _dest[i];
     if (i + 1 &lt; _dest.Count)
       _resultPath += &quot;\\&quot;;
    }

   }
   else
   {

     for (int i = 0; i &lt; _from.Count; i++)
     {
      _resultPath += &quot;..\\&quot;;
     }

     for (int i = 0; i &lt; _dest.Count; i++)
     {
      _resultPath += _dest[i];
      if (i + 1 &lt; _dest.Count)
        _resultPath += &quot;\\&quot;;
     }
   }
   return _resultPath;
 }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=98</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[C#] How to associate user component with other component which is null at initialization</title>
		<link>http://itblog.socar.pl/?p=91</link>
		<comments>http://itblog.socar.pl/?p=91#comments</comments>
		<pubDate>Sat, 17 Oct 2009 19:56:31 +0000</pubDate>
		<dc:creator>SOCAR</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[ComponentDesigner]]></category>

		<guid isPermaLink="false">http://itblog.socar.pl/?p=91</guid>
		<description><![CDATA[Problem: The idea is to put my own component on form and associate it with already existing TabControl object. Also, I wanted to capture user pressed keys and react on them before they will reach other controls (which require to set KeyPreview to true and add KeyDown/KeyUp event). Willing to encapsulate this process behind developer [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Problem:</strong></p>
<p>The idea is to put my own component on form and associate it with already existing <em>TabControl</em> object. Also, I wanted to capture user pressed keys and react on them before they will reach other controls (which require to set <em>KeyPreview</em> to true and add <em>KeyDown/KeyUp </em> event). Willing to encapsulate this process behind developer eyes, I write appropriate code in property of my component. But when I added control in <em>Component Designer</em> I was receiving error while starting application, initialize code of my component was written in <em>InitializeComponent()</em> method before the base <em>Form</em> object was initialized. Like this:</p>
<pre class="brush: csharp;">

void InitializeComponent()
{
//....
//
// MyComponent
//
this.myComponent.ParentTab = this.tabControl1;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(522, 273);
this.Controls.Add(this.tabControl1);
this.KeyPreview = true;
this.Name = &quot;Form1&quot;;
this.Text = &quot;Form1&quot;;
this.myComponent1.ResumeLayout(false);
this.ResumeLayout(false);
}
</pre>
<p>And in my code I was calling the uninitialized code:</p>
<pre class="brush: csharp;">

//...
myComponent1.FindForm().KeyDown += //...
</pre>
<p><em>FindForm() </em>was returning null (as the form wasn&#8217;t yet initialized)</p>
<p><strong>Solution:</strong></p>
<ol>
<li>Create KeyDown (or any) event for the TabControl itself</li>
<li>At runtime, check in KeyDown state of the form you want to hook to. If it&#8217;s null, you can use the <em>FindForm()</em> because at runtime all controls are already initialized !</li>
</ol>
<p>Solution was implemented in <em>TabSwitcher </em>component I wrote, for the <em>TabControl</em> control.</p>
<p>It&#8217;s that simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://itblog.socar.pl/?feed=rss2&amp;p=91</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
