<?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>dotnet thoughts &#187; VB.Net</title>
	<atom:link href="http://www.dotnetthoughts.net/tag/vb-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dotnetthoughts.net</link>
	<description>a dotnet developer&#039;s technical blog</description>
	<lastBuildDate>Thu, 02 Feb 2012 03:18:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to associate a File Type to your application</title>
		<link>http://www.dotnetthoughts.net/2011/02/15/how-to-associate-a-file-type-to-your-application/</link>
		<comments>http://www.dotnetthoughts.net/2011/02/15/how-to-associate-a-file-type-to-your-application/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 01:20:15 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[.Net 4.0]]></category>
		<category><![CDATA[File Association]]></category>
		<category><![CDATA[registry]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=1478</guid>
		<description><![CDATA[Recently I was working with an Open source project which helps to manage SQLCE databases. Yesterday I thought of implementing a feature like associating the SDF files to my application, so that I can double click on any SDF file &#8230; <a href="http://www.dotnetthoughts.net/2011/02/15/how-to-associate-a-file-type-to-your-application/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently I was working with an Open source project which helps to manage SQLCE databases. Yesterday I thought of implementing a feature like associating the SDF files to my application, so that I can double click on any SDF file which will open the launch my application and opens the File in it.</p>
<p><strong>Caution</strong>: Incorrectly editing the registry may severely damage your system. Back up the current version of the registry before making any changes. You should also back up any valued data on the computer.</p>
<p>I found various ways to do it, but the easy way I found I am sharing.</p>
<pre class="brush: vb; title: ; notranslate">
Dim SDF As RegistryKey = My.Computer.Registry.ClassesRoot. _
    CreateSubKey(&quot;.sdx&quot;)
SDF.SetValue(&quot;&quot;, &quot;SDFUtility&quot;, RegistryValueKind.String)
Dim OpenCommand As RegistryKey =
    My.Computer.Registry.ClassesRoot.CreateSubKey _
    (&quot;SDFUtility\Shell\Explore with SDFUtility\Command&quot;)
OpenCommand.SetValue(&quot;&quot;, String.Format(&quot;{0} &quot;&quot;%1&quot;&quot;&quot;, appPath), _
                        Microsoft.Win32.RegistryValueKind.String)
</pre>
<p>And here is the screenshot</p>
<div id="attachment_1479" class="wp-caption aligncenter" style="width: 271px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2011/02/right_click.jpg"><img class="size-full wp-image-1479" title="Default menu item after associating the File with application" src="http://www.dotnetthoughts.net/wp-content/uploads/2011/02/right_click.jpg" alt="Default menu item after associating the File with application" width="261" height="61" /></a><p class="wp-caption-text">Default menu item after associating the File with application</p></div>
<p>You can remove the association by reseting the sdf key&#8217;s value. And you can delete all the keys by calling a DeleteSubKeyTree method on the SDFUtility key to remove all the keys associated with it.</p>
<pre class="brush: vb; title: ; notranslate">
SDF = My.Computer.Registry.ClassesRoot.OpenSubKey(&quot;.sdf&quot;, True)
SDF.SetValue(&quot;&quot;, &quot;Microsoft SQL Server Compact Edition Database File&quot;, _
                     RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.DeleteSubKeyTree(&quot;SDFUtility&quot;)
</pre>
<p>You need be Administrator do this operation, otherwise you may get an exception in Windows Vista+. </p>
<div class="betterrelated none"><p>No related content found.</p></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2011/02/15/how-to-associate-a-file-type-to-your-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Places in FileDialog box</title>
		<link>http://www.dotnetthoughts.net/2010/06/21/custom-places-in-filedialog-box/</link>
		<comments>http://www.dotnetthoughts.net/2010/06/21/custom-places-in-filedialog-box/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 04:06:18 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[WPF]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[FileDialog]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=925</guid>
		<description><![CDATA[If you ever tried to Open a File from Visual Studio, you may notice something like Projects Folder in the Open File Dialog. We can also implement the same functionality in our applications by using CustomPlaces collection property of FileDialog &#8230; <a href="http://www.dotnetthoughts.net/2010/06/21/custom-places-in-filedialog-box/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you ever tried to Open a File from Visual Studio, you may notice something like Projects Folder in the Open File Dialog.</p>
<div id="attachment_926" class="wp-caption aligncenter" style="width: 209px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/06/openfile_vs2010.png"><img class="size-full wp-image-926" title="Open File Dialog in Visual Studio" src="http://www.dotnetthoughts.net/wp-content/uploads/2010/06/openfile_vs2010.png" alt="Open File Dialog in Visual Studio" width="199" height="398" /></a><p class="wp-caption-text">Open File Dialog in Visual Studio</p></div>
<p>We can also implement the same functionality in our applications by using  CustomPlaces collection property of FileDialog class. The OpenFileDialog and SaveFileDialog classes allow you to add folders to the CustomPlaces collection.</p>
<pre class="brush: csharp; title: ; notranslate">
openFileDialog.CustomPlaces.Add(@&quot;C:\Users&quot;);
</pre>
<p>You can also specify GUID of Windows Vista known folder. Known Folder GUIDs are not case sensitive and are defined in the KnownFolders.h file in the Windows SDK. If the specified Known Folder is not present on the computer that is running the application, the Known Folder is not shown.</p>
<pre class="brush: csharp; title: ; notranslate">
openFileDialog.CustomPlaces.Add(@&quot;C:\Users&quot;);
//Desktop Folder
openFileDialog.CustomPlaces.Add(new Guid(&quot;B4BFCC3A-DB2C-424C-B029-7FE99A87C641&quot;));
//Downloads Folder
openFileDialog.CustomPlaces.Add(new Guid(&quot;374DE290-123F-4565-9164-39C4925E467B&quot;));
</pre>
<div id="attachment_929" class="wp-caption aligncenter" style="width: 417px"><a href="http://www.dotnetthoughts.net/wp-content/uploads/2010/06/openfile_custom.png"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2010/06/openfile_custom.png" alt="Open File Dialog with Custom Places " title="Open File Dialog with Custom Places " width="407" height="479" class="size-full wp-image-929" /></a><p class="wp-caption-text">Open File Dialog with Custom Places </p></div>
<p>Note: This feature will not have any effect in Windows XP. Also you must set the AutoUpgradeEnabled to True(default) to enable this feature in Vista or Windows 7.</p>
<p>The following table lists few Windows Vista Known Folders and their associated Guid.  </p>
<ol>
<li>Contacts : 56784854-C6CB-462B-8169-88E350ACB882</li>
<li>ControlPanel : 82A74AEB-AEB4-465C-A014-D097EE346D63</li>
<li>Desktop : B4BFCC3A-DB2C-424C-B029-7FE99A87C641</li>
<li>Documents : FDD39AD0-238F-46AF-ADB4-6C85480369C7</li>
<li>Downloads : 374DE290-123F-4565-9164-39C4925E467B</li>
<li>Favorites : 1777F761-68AD-4D8A-87BD-30B759FA33DD</li>
<li>Fonts : FD228CB7-AE11-4AE3-864C-16F3910AB8FE</li>
<li>Music : 4BD8D571-6D19-48D3-BE97-422220080E43</li>
</ol>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2010/09/01/create-uac-compatible-applications-in-net/" title="Permanent link to Create UAC Compatible applications in .NET">Create UAC Compatible applications in .NET</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/06/30/how-to-use-taskdialog-api-in-c/" title="Permanent link to How to use TaskDialog API in C#">How to use TaskDialog API in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/11/02/wpf-interoperability-with-windows-forms/" title="Permanent link to WPF interoperability with Windows Forms">WPF interoperability with Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/08/25/how-to-disable-close-button-of-windows-forms-application/" title="Permanent link to How to disable Close button of Windows Forms Application">How to disable Close button of Windows Forms Application</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/10/07/how-to-store-and-retrieve-files-from-sql-server-database/" title="Permanent link to How to Store and Retrieve files from SQL Server Database">How to Store and Retrieve files from SQL Server Database</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2010/06/21/custom-places-in-filedialog-box/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Application development using Gtk# in .Net</title>
		<link>http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 02:53:04 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[.Net 3.0 / 3.5]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Windows Forms]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Gtk]]></category>
		<category><![CDATA[Mono]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=532</guid>
		<description><![CDATA[When I started my software development career, I got introduced to some cool tools for GUI application development in Linux. I was using Glade and the library was Gtk. Then later I become a MS fan and started working on &#8230; <a href="http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When I started my software development career, I got introduced to some cool tools for GUI application development in Linux. I was using Glade and the library was Gtk. Then later I become a MS fan and started working on ASP, VB and .Net. Yesterday I got a chance to download Mono and Monodevelop. And the Gtk for Windows and .Net called Gtk#. I explored in Mono Develop(I was downloaded MonoDevelop-2.2 beta 2) a little, but it was crashed for me two time. <img src='http://www.dotnetthoughts.net/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Then I started using Gtk# in VC# Express. And I created a simple Text File Viewer using C#, with Gtk# for UI. Most of the things in Gtk# is pretty different from .Net Windows Forms development. And I like the concept to in built support for predefined MenuItems, Icons etc. I think MS took the idea of commands in WPF from this.</p>
<p>I created a Windows Application Project and Added reference of the following libraries</p>
<p>atk-sharp.dll<br />
gdk-sharp.dll<br />
glade-sharp.dll<br />
glib-sharp.dll<br />
gtk-dotnet.dll<br />
gtk-sharp.dll</p>
<p>And I deleted the Form1. And modified the Program.cs; the Program.cs</p>
<pre class="brush: csharp; title: ; notranslate">
namespace HelloGtk
{
    using System;
    using Gtk;

    public class Program
    {
        private MainWindow mainWindow = null;

        public Program()
        {
            Application.Init();
            mainWindow = new MainWindow();
            Application.Run();
        }

        static void Main()
        {
            new Program();
            return;
        }
    }
}
</pre>
<p>And the added a class MainWindow.cs, and wrote the code</p>
<pre class="brush: csharp; title: ; notranslate">
namespace HelloGtk
{
    using Gtk;
    using System.IO;

    public class MainWindow : Gtk.Window
    {
        private string title = &quot;Text File Viewer&quot;;
        private VBox vbox;
        private MenuBar menubar;
        private Statusbar statusbar;
        private TextView textView;
        private ScrolledWindow scrolledWindow;
        private AccelGroup accelGroup;
        private Toolbar toolbar;
        public MainWindow()
            : base(&quot;Text File Viewer&quot;)
        {
            this.DefaultSize = new Gdk.Size(600, 500);
            this.DeleteEvent += new DeleteEventHandler(MainWindow_DeleteEvent);
            this.Build();
        }

        private void MainWindow_DeleteEvent(object o, DeleteEventArgs args)
        {
            Application.Quit();
            args.RetVal = true;
        }

        private void Build()
        {
            this.Title = this.title;
            this.vbox = new VBox(false, 0);
            this.CreateMenubar();
            this.vbox.PackStart(this.menubar, false, true, 0);
            this.toolbar = new Toolbar();
            this.CreateToolbar();
            this.vbox.PackStart(this.toolbar, false, true, 0);
            this.textView = new TextView();
            this.textView.Editable = false;
            this.textView.WrapMode = WrapMode.Word;
            this.scrolledWindow = new ScrolledWindow();
            this.scrolledWindow.SetPolicy(PolicyType.Automatic, PolicyType.Automatic);
            this.scrolledWindow.Add(this.textView);
            this.vbox.PackStart(this.scrolledWindow, true, true, 0);
            this.statusbar = new Statusbar();
            this.vbox.PackStart(this.statusbar, false, true, 0);
            this.Add(this.vbox);
            this.ShowAll();
        }
        private void CreateToolbar()
        {
            ToolButton OpenToolBarBtn = new ToolButton(&quot;gtk-open&quot;);
            OpenToolBarBtn.Clicked += this.openMenu_Activated;
            SeparatorToolItem Sep1 = new SeparatorToolItem();
            ToolButton CopyToolBarBtn = new ToolButton(&quot;gtk-copy&quot;);
            CopyToolBarBtn.Clicked += this.copyMenu_Activated;
            SeparatorToolItem Sep2 = new SeparatorToolItem();
            ToolButton AboutToolBarBtn = new ToolButton(&quot;gtk-about&quot;);
            AboutToolBarBtn.Clicked += this.aboutMenu_Activated;

            this.toolbar.Add(OpenToolBarBtn);
            this.toolbar.Add(Sep1);
            this.toolbar.Add(CopyToolBarBtn);
            this.toolbar.Add(Sep2);
            this.toolbar.Add(AboutToolBarBtn);
        }

        private void CreateMenubar()
        {
            this.accelGroup = new AccelGroup();
            this.menubar = new MenuBar();
            MenuItem fileMenu = new MenuItem(&quot;_File&quot;);
            MenuItem editMenu = new MenuItem(&quot;_Edit&quot;);
            MenuItem helpMenu = new MenuItem(&quot;_Help&quot;);
            helpMenu.RightJustified = true;

            Menu fileSubMenu = new Menu();
            TearoffMenuItem fileMenuTearOff = new TearoffMenuItem();
            ImageMenuItem openMenu = new ImageMenuItem(&quot;gtk-open&quot;, accelGroup);
            openMenu.Activated += new System.EventHandler(openMenu_Activated);
            SeparatorMenuItem fileMenuSep = new SeparatorMenuItem();
            ImageMenuItem exitMenu = new ImageMenuItem(&quot;gtk-quit&quot;, accelGroup);
            exitMenu.Activated += new System.EventHandler(exitMenu_Activated);
            fileSubMenu.Add(fileMenuTearOff);
            fileSubMenu.Add(openMenu);
            fileSubMenu.Add(fileMenuSep);
            fileSubMenu.Add(exitMenu);
            fileMenu.Submenu = fileSubMenu;

            Menu editSubMenu = new Menu();
            ImageMenuItem copyMenu = new ImageMenuItem(&quot;gtk-copy&quot;, accelGroup);
            copyMenu.Activated += new System.EventHandler(copyMenu_Activated);
            TearoffMenuItem editMenuTearOff = new TearoffMenuItem();
            editSubMenu.Add(editMenuTearOff);
            editSubMenu.Add(copyMenu);
            editMenu.Submenu = editSubMenu;

            Menu helpSubMenu = new Menu();
            ImageMenuItem aboutMenu = new ImageMenuItem(&quot;gtk-about&quot;, accelGroup);
            TearoffMenuItem helpMenuTearOff = new TearoffMenuItem();
            helpSubMenu.Add(helpMenuTearOff);
            helpSubMenu.Add(aboutMenu);
            aboutMenu.Activated += new System.EventHandler(aboutMenu_Activated);
            helpMenu.Submenu = helpSubMenu;

            this.menubar.Add(fileMenu);
            this.menubar.Add(editMenu);
            this.menubar.Add(helpMenu);
        }

        void aboutMenu_Activated(object sender, System.EventArgs e)
        {
            using (Dialog dialog = new MessageDialog(this,
                                  DialogFlags.Modal | DialogFlags.DestroyWithParent,
                                  MessageType.Info,
                                  ButtonsType.Ok,
                                  &quot;Text File Viewer - A simple text file viewer using gtk#\nDeveloped by Anuraj\nPowered by dotnetthoughts.net\n\nUnder GNU GPL v2.&quot;))
            {
                dialog.Title = &quot;About&quot;;
                dialog.Run();
                dialog.Hide();
            }
        }

        private void copyMenu_Activated(object sender, System.EventArgs e)
        {
            Clipboard clipboad = this.textView.GetClipboard(Gdk.Selection.Clipboard);
            this.textView.Buffer.CopyClipboard(clipboad);
        }

        void exitMenu_Activated(object sender, System.EventArgs e)
        {
            Application.Quit();
        }
        FileChooserDialog dlg;
        private void openMenu_Activated(object sender, System.EventArgs e)
        {
            dlg =
                new FileChooserDialog(&quot;Select Text File&quot;, this, FileChooserAction.Open, &quot;&quot;);
            dlg.AddButton(&quot;Open File&quot;, ResponseType.Ok);
            dlg.AddButton(&quot;Cancel&quot;, ResponseType.Cancel);

            FileFilter filter = new FileFilter();
            filter.AddPattern(&quot;*.txt&quot;);
            filter.AddPattern(&quot;*.*&quot;);
            dlg.Filter = filter;

            dlg.TypeHint = Gdk.WindowTypeHint.Dialog;
            dlg.SelectMultiple = false;
            dlg.WindowPosition = WindowPosition.Center;
            dlg.Parent = this;
            dlg.Modal = true;
            dlg.KeepAbove = true;
            dlg.DestroyWithParent = true;
            dlg.State = StateType.Normal;

            dlg.Response += new ResponseHandler(dlg_Response);
            dlg.DeleteEvent += new DeleteEventHandler(dlg_DeleteEvent);

            dlg.Run();
            dlg.Destroy();

        }

        private void dlg_DeleteEvent(object o, DeleteEventArgs args)
        {
            dlg.Destroy();
        }

        private void dlg_Response(object o, ResponseArgs args)
        {
            if (args.ResponseId == ResponseType.Ok)
            {
                this.Title = string.Format(&quot;{0} - {1}&quot;, this.title, System.IO.Path.GetFileName(dlg.Filename));
                using (StreamReader reader = new StreamReader(dlg.Filename, true))
                {
                    this.textView.Buffer.Text = reader.ReadToEnd();
                }
            }
            dlg.Destroy();
        }
    }
}
</pre>
<p>And run the application. Here is the screenshot, Text File Viewer running on my machine.</p>
<div id="attachment_541" class="wp-caption alignnone" style="width: 510px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/10/Text_File_Viewer_Using_GTK.jpg" alt="Text File Viewer using GTK#" title="Text File Viewer using GTK#" width="500" height="326" class="size-full wp-image-541" /><p class="wp-caption-text">Text File Viewer using GTK#</p></div>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2009/11/16/webcam-in-your-applications-using-c/" title="Permanent link to WebCam in your applications using C#">WebCam in your applications using C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/07/28/uploading-files-using-webservice/" title="Permanent link to Uploading Files using Webservice">Uploading Files using Webservice</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/01/06/file-uploader-using-silverlight-and-wcf/" title="Permanent link to File Uploader using Silverlight and WCF">File Uploader using Silverlight and WCF</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/12/17/developing-a-simple-rss-reader-in-c-net/" title="Permanent link to Developing a simple RSS Reader in C#.Net">Developing a simple RSS Reader in C#.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/06/22/customize-spellcheck-in-wpf-textbox/" title="Permanent link to Customize SpellCheck in WPF textbox">Customize SpellCheck in WPF textbox</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/17/application-development-using-gtk-in-net/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Color Picker Dropdown using C#</title>
		<link>http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 04:05:52 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[Color Picker]]></category>
		<category><![CDATA[Drawing]]></category>
		<category><![CDATA[Drawmode]]></category>
		<category><![CDATA[Dropdown]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=527</guid>
		<description><![CDATA[While playing around one of hobby project, I found there is a nice color picker dropdown available in WordPad, for setting the font color. I was using Windows Color Dialog. So I thought of implementing a WordPad like color picker. &#8230; <a href="http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>While playing around one of hobby project, I found there is a nice color picker dropdown available in WordPad, for setting the font color. I was using Windows </p>
<p>Color Dialog. So I thought of implementing a WordPad like color picker. And I think I almost readed my goal. I need to try this in the Toolstrip dropdown too.</p>
<pre class="brush: csharp; title: ; notranslate">
//On the Form load I am loading the colors to the Dropdown.
//You can also bind the p to the Dropdown.
Type t = typeof(Color);
PropertyInfo[] p = t.GetProperties();
foreach (PropertyInfo item in p)
{
    if (item.PropertyType.FullName.Equals(&quot;System.Drawing.Color&quot;, StringComparison.CurrentCultureIgnoreCase))
    {
        this.comboBox1.Items.Add(item.Name);
    }
}
</pre>
<p>And I set the Dropdown&#8217;s DrawMode property to &#8220;OwnerDrawFixed&#8221;. And in the DrawItem event of the Dropdown I wrote the code.</p>
<pre class="brush: csharp; title: ; notranslate">
if (e.Index != -1)
{
    e.DrawBackground();
    e.Graphics.FillRectangle(GetCurrentBrush(comboBox1.Items[e.Index].ToString()), e.Bounds);
    Font f = comboBox1.Font;
    e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), f, Brushes.Black, e.Bounds, StringFormat.GenericDefault);
    e.DrawFocusRectangle();
}
</pre>
<p>And the GetCurrentBrush() function returns the Brush for painting the rectangle. You can write the code in the DrawItem event too, but initialy I thought about setting the font color using the same color. But later that idea changed.</p>
<pre class="brush: csharp; title: ; notranslate">
private Brush GetCurrentBrush(string colorName)
{
    return new SolidBrush(Color.FromName(colorName));
}
</pre>
<p>One issue I found in this code is, for black color, I can&#8217;t see the color name. And here is the screenshot of Color Picker Dropdown running on my machine.</p>
<div id="attachment_529" class="wp-caption alignnone" style="width: 285px"><img src="http://www.dotnetthoughts.net/wp-content/uploads/2009/10/color_dropdown.PNG" alt="Color Picker Dropdown screenshot" title="Color Picker Dropdown screenshot" width="275" height="385" class="size-full wp-image-529" /><p class="wp-caption-text">Color Picker Dropdown screenshot</p></div>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2007/04/17/font-enumeration-in-vbnet/" title="Permanent link to Font Enumeration in VB.Net">Font Enumeration in VB.Net</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/10/18/how-to-add-simple-water-mark-to-images/" title="Permanent link to How to add simple water mark to images">How to add simple water mark to images</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/03/06/creating-color-picker-application-in-c/" title="Permanent link to Creating color picker application in C#">Creating color picker application in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/09/15/captcha-using-asp-net-and-c/" title="Permanent link to Captcha using ASP.Net and C#">Captcha using ASP.Net and C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/11/08/implementing-close-button-in-tab-pages/" title="Permanent link to Implementing Close button in Tab Pages">Implementing Close button in Tab Pages</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/15/color-picker-dropdown-using-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to check remote file exists using C#</title>
		<link>http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/</link>
		<comments>http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 06:49:25 +0000</pubDate>
		<dc:creator>Anuraj P</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[C#.Net]]></category>
		<category><![CDATA[File Existance]]></category>
		<category><![CDATA[Remote File exists]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[Windows Forms]]></category>

		<guid isPermaLink="false">http://www.dotnetthoughts.net/?p=493</guid>
		<description><![CDATA[Sometime you require to display remote images in the Web Pages, like Ads, Banner etc, it may be from different domain or a different application. This code will help you to check the existence of a Remote file using C#. &#8230; <a href="http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometime you require to display remote images in the Web Pages, like Ads, Banner etc, it may be from different domain or a different application. This code will help you to check the existence of a Remote file using C#.</p>
<pre class="brush: csharp; title: ; notranslate">
using System.Net;

///
/// Checks the file exists or not.
///
/// The URL of the remote file.
/// True : If the file exits, False if file not exists
private bool RemoteFileExists(string url)
{
    try
    {
        //Creating the HttpWebRequest
        HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
        //Setting the Request method HEAD, you can also use GET too.
        request.Method = &quot;HEAD&quot;;
        //Getting the Web Response.
        HttpWebResponse response = request.GetResponse() as HttpWebResponse;
        //Returns TURE if the Status code == 200
        return (response.StatusCode == HttpStatusCode.OK);
    }
    catch
    {
        //Any exception will returns false.
        return false;
    }
}
</pre>
<p>You can also use WebClient class for the same purpose. Like this.</p>
<pre class="brush: csharp; title: ; notranslate">
using System.Net;

///
/// Checks the file exists or not.
///
/// The URL of the remote file.
/// True : If the file exits, False if file not exists
private bool RemoteFileExists(string url)
{
    bool result = false;
    using (WebClient client = new WebClient())
    {
        try
        {
            Stream stream = client.OpenRead(url);
            if (stream != null)
            {
                result = true;
            }
            else
            {
                result = false;
            }
        }
        catch
        {
            //Any exception will returns false.
            result = false;
        }
    }
    return result;
}
</pre>
<p>Internally WebClient is using the HttpWebRequest and HttpWebResponse classes, so it is good to use the first method.</p>
<div class="betterrelated"><p><strong>Related content:</strong></p>
<ol><li> <a href="http://www.dotnetthoughts.net/2009/11/10/post-data-using-httpwebrequest-in-c-sharp/" title="Permanent link to Post data using HttpWebRequest in C#">Post data using HttpWebRequest in C#</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2009/05/19/loading-image-from-url-in-windows-forms/" title="Permanent link to Loading Image from URL in Windows Forms">Loading Image from URL in Windows Forms</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/11/26/how-to-upload-file-using-httpwebrequest-class/" title="Permanent link to How to upload file using HttpWebRequest class">How to upload file using HttpWebRequest class</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2011/07/17/upload-multiple-files-using-silverlight/" title="Permanent link to Upload multiple files using Silverlight">Upload multiple files using Silverlight</a>  </li>
<li> <a href="http://www.dotnetthoughts.net/2010/01/05/http-compression-in-asp-net/" title="Permanent link to Http Compression in ASP.Net">Http Compression in ASP.Net</a>  </li>
</ol></div>]]></content:encoded>
			<wfw:commentRss>http://www.dotnetthoughts.net/2009/10/14/how-to-check-remote-file-exists-using-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

