desktop color picker

  • Thread starter Thread starter sajin
  • Start date Start date
S

sajin

Hi all,

I am a new comer in VB .net windows forms , i need to implement a color
picker which is used to select color anywhere from the screen , i
searched in the net but no info


Plz give me some information
Thanks in advance

Regards
Sajin
 
Windows Forms Tips and Tricks has an article on finding the colour under the
cursor.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 
This i implemented in vb .net 2005 and the codes are below
But here the colors are displayed in the form itself , i need to select
anywhere from the desktop

Imports System
Imports System.Runtime.InteropServices
Imports System.Drawing
Imports System.Collections
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Data
Public Class Form1
Inherits System.Windows.Forms.Form
<DllImport("Gdi32.dll")> Public Shared Function GetPixel(ByVal hdc
As System.IntPtr, ByVal nXPos As Integer, ByVal nYPos As Integer) As
Integer
End Function
<DllImport("User32.dll")> Public Shared Function GetDC(ByVal wnd As
IntPtr) As IntPtr
End Function
<DllImport("User32.dll")> Public Shared Sub ReleaseDC(ByVal dc As
IntPtr)
End Sub
Private panel1 As System.Windows.Forms.Panel
Private WithEvents timer1 As System.Timers.Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Me.panel1 = New System.Windows.Forms.Panel
Me.timer1 = New System.Timers.Timer
CType(Me.timer1,
System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'panel1
'
Me.panel1.BorderStyle =
System.Windows.Forms.BorderStyle.Fixed3D
Me.panel1.Location = New System.Drawing.Point(216, 8)
Me.panel1.Name = "panel1"
Me.panel1.Size = New System.Drawing.Size(64, 56)
Me.panel1.TabIndex = 0
'
'timer1
'
Me.timer1.Enabled = True
Me.timer1.SynchronizingObject = Me
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.BackColor = System.Drawing.Color.White
Me.ClientSize = New System.Drawing.Size(292, 273)
Me.Controls.Add(Me.panel1)
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.timer1,
System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim r As New Random(1)
Dim x As Integer
For x = 0 To 99
Dim b As New SolidBrush(Color.FromArgb(r.Next(255),
r.Next(255), r.Next(255)))
e.Graphics.FillRectangle(b, r.Next(Me.ClientSize.Width),
r.Next(Me.ClientSize.Height), r.Next(100), r.Next(100))
Next x
End Sub
Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
Dim g As Graphics = Me.CreateGraphics()
Dim myDC As IntPtr = g.GetHdc()
Dim c As Color = ColorTranslator.FromWin32(GetPixel(myDC, e.X,
e.Y))
g.ReleaseHdc(myDC)
Me.panel1.BackColor = c
End Sub 'OnMouseMove
End Class



Help me , for that what i should do

Thanks
Sajin
 
Back
Top