Click here to Skip to main content
13,355,538 members (76,983 online)
Click here to Skip to main content
Add your own
alternative version


12 bookmarked
Posted 30 Sep 2007

Color Grabber

, 19 Feb 2010
Rate this:
Please Sign up or sign in to vote.
A utility to catch a color from the desktop
Screenshot - ColorGrabber.jpg


This is a utility to capture a color from the desktop.


I needed an HTML color in a web project, but because I only had a bitmap of the page, I didn't know the colors.

Then I remembered I had a utility written in VB6. I decided to transpose it to VB.NET and add the HTML-color-code to the result.

Using the Code

The utility is quite easy to use. Just run the EXE, click the Go button, and move the mouse around.

When the Go-button is clicked, I catch the desktop and display it as an image on a secondary form displayed underneath the main form. The color of the pixel under the hot spot is displayed in the main form window, and is displayed both in RGB and HTML-code.

By clicking when the "right" color is displayed, the HTML-code is put in the clipboard.

Points of Interest

The old VB6-code was much more verbose. The Form.BackgroundImage property reduced the code a lot. This line of code:

Me.BackgroundImage = PerformCapture()

replaces a lot more VB6 code lines.

Since I don't know of an easy way to find which APIs are embedded in the framework, I kept the old API calls.

For example:

<System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")> _ 
Private Shared Function BitBlt(ByVal hdcDest As IntPtr, 
    ByVal nXDest As Int32, ByVal nYDest As Int32, ByVal nWidth As Int32, 
    ByVal nHeight As Int32, ByVal hdcSrc As IntPtr, _ ByVal nXSrc As Int32, 
    ByVal nYSrc As Int32, ByVal dwRop As Int32) As Boolean End Function 

Declare Auto Function CreateDC Lib "gdi32" (ByVal lpDriverName As String, 
    _ ByVal lpDeviceName As String, ByVal lpOutput As String, 
    ByVal lpInitData As IntPtr) As IntPtr

This also shows two different ways of declaring an API in VB.NET.


  • 1st October, 2007: Initial post
  • 17th February, 2010: Made some code changes and an upgrade to Visual Studio 2008


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Michael Rosqvist
Web Developer
Sweden Sweden
No Biography provided

You may also be interested in...

Comments and Discussions

GeneralMy vote of 1 Pin
Johnny J.20-Feb-10 0:53
memberJohnny J.20-Feb-10 0:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180111.1 | Last Updated 19 Feb 2010
Article Copyright 2007 by Michael Rosqvist
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid