Can Vb6 give me the color code of something I click on the form?
Hi there, I am teaching the students about map keys/legends in social studies. Basically I have a map that has provinces in different colors. To introduce how a map legend works I want the students to click a part of the map, and then click on an vb6 shape, and the color fill will be the same as the part of the map/province they picked. That way, they can learn the legend colors tells them which province is which.
I know paint.net has a duplicate color option somewhere, but I am just looking for something simple for my class.
Re: Can Vb6 give me the color code of something I click on the form?
have a form or picturebox with a picture in it and a labelcontrol:
Code:
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = Me.Point(X, Y)
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Label1.BackColor = Picture1.Point(X, Y)
End Sub
do not put off till tomorrow what you can put off forever
Re: Can Vb6 give me the color code of something I click on the form?
Eduardo
Forgive me, but for "quick consumption" purposes, I've posted your code below
Code:
Option Explicit
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As POINTAPI) As Long
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
Private Sub Timer1_Timer()
Dim iPt As POINTAPI
Dim iColor As Long
Dim iHwnd As Long
Dim iDc As Long
If (GetAsyncKeyState(vbKeyLButton) < 0) Then
GetCursorPos iPt
iHwnd = WindowFromPoint(iPt.X, iPt.Y)
If IsLocal(iHwnd) Then
ScreenToClient iHwnd, iPt
iDc = GetDC(iHwnd)
If iDc <> 0 Then
iColor = GetPixel(iDc, iPt.X, iPt.Y)
If iColor > -1 Then
Picture1.BackColor = iColor
End If
End If
End If
End If
End Sub
Private Function IsLocal(nHwnd As Long) As Boolean
Dim iCtl As Control
Dim iHwnd As Long
If nHwnd = Me.hWnd Then
IsLocal = True
Else
On Error Resume Next
For Each iCtl In Me.Controls
iHwnd = iCtl.hWnd
If iHwnd = nHwnd Then
IsLocal = True
Exit For
End If
Next
End If
End Function
There's also this bit (strictly speaking, not code)
Code:
Begin VB.Timer Timer1
Interval = 50
Left = 144
Top = 288
End
Re: Can Vb6 give me the color code of something I click on the form?
Originally Posted by Spooman
There's also this bit (strictly speaking, not code)
Code:
Begin VB.Timer Timer1
Interval = 50
Left = 144
Top = 288
End
Hey Spoo,
Sorry, but I just can't help myself. IMHO, that's absolutely code. It's code that defines the form/controls for user interface. It's just not code that was typed into a VB6 IDE code window. Rather, it was created by the drag-and-drop operations of creating a form in the VB6 IDE.
Do you ever use MS-Access to create queries? These days, we often do this with the drag-and-drop operations from the MS-Access query tab. However, we can always click the SQL button and see the SQL code that's being written from our drag-and-drop operations. Would you say that the SQL lines that the drag-and-drop query creation are code? I think you'd have to. In that same vane, I think we're compelled to say that our form/control definition "code" is also code.
Just gettin' your goat.
Take Care,
Elroy
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.
Re: Can Vb6 give me the color code of something I click on the form?
Hey Spoo,
Truth be told, I've never become the wiz-kid at writing SQL. Part of the reason is that I mostly use the DAO for accessing MDB files from VB6. And also, I just get done what I need and call it a day, without ever having to dig that deeply into all the power of SQL.
However, a "trick" I've used many times is to open MS-Access, develop a certain query in MS-Access that works the way I want, and then copy-paste that query's SQL code into a VB6 string for use in creating a RecordSet. It's a nifty trick. It's similar to the trick of recording a macro in MS-Word (or MS-Excel) that does something, and then copy-paste that macro's code into VB6.
You Take Care,
Elroy
EDIT1: Hey Justin, I apologize for causing your thread to veer off-course. I'm hoping you have your problem solved. If not, please say so.
Any software I post in these forums written by me is provided "AS IS" without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. To all, peace and happiness.