Rank: Advanced Member Groups: Administration
, Member
Joined: 1/31/2005 Posts: 369 Points: 352
|
This is reincarnation of Color Picker Sample from Graphics Mill ActiveX forum. The essential code is listed below, full project can be found in attachments. Code:
Public Class Form1
Private _screenGraphics As Aurigma.GraphicsMill.Drawing.GdiGraphics
Private _capturing As Boolean
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As IntPtr) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_screenGraphics = Aurigma.GraphicsMill.Drawing.GdiGraphics.FromHwnd(IntPtr.Zero)
End Sub
Private Sub _pickButton_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _pickButton.MouseDown
SetCapture(_pickButton.Handle)
Me.Cursor = System.Windows.Forms.Cursors.Help
_capturing = True
End Sub
Private Sub _pickButton_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _pickButton.MouseUp
ReleaseCapture()
Me.Cursor = System.Windows.Forms.Cursors.Default
_capturing = False
End Sub
Private Sub _pickButton_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles _pickButton.MouseMove
If _capturing Then
Dim screenPoint As System.Drawing.Point = _pickButton.PointToScreen(e.Location)
_coordsTextBox.Text = String.Format("X: {0} Y: {1}", screenPoint.X, screenPoint.Y)
Dim color As System.Drawing.Color = _screenGraphics.GetPixel(screenPoint.X, screenPoint.Y)
_colorPanel.BackColor = color
_colorTextBox.Text = color.ToString()
End If
End Sub
End Class
Feel free to ask if you have any questions or discuss the posted code. If you need C# version - do not hesitate to contact us, we surely will provide it. File Attachment(s):
ColorPickerSample.zip (1,379kb) downloaded 29 time(s).
Best wishes, Alex.
|