|
-
Nov 28th, 2007, 05:18 AM
#1
Thread Starter
Hyperactive Member
How to get control Backcolor and store as OLE_COLOR
Hi all,
I had tried a lot of time but i can't get the solution of my problem.
Now i would like to use a variable as OLE_COLOR to store the backcolor of a
Label. When the user mousemove to the label the Variable will store the
backcolor of the label and the label will change to others color. Following it,
when i mousemove at outside the label, the label backcolor will access the
color store in variable.
How can i do that ?
Thanks for help
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Nov 28th, 2007, 07:18 AM
#2
Re: How to get control Backcolor and store as OLE_COLOR
Fundamentally, you question is: how do I change the backcolor of a label when the mouse is over it, and then change it back to whatever the original color was when the mouse leaves it, right?
-
Nov 28th, 2007, 07:19 AM
#3
Thread Starter
Hyperactive Member
Re: How to get control Backcolor and store as OLE_COLOR
Yes you are right , Perfect ...
Hack please help me .!!
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Nov 28th, 2007, 07:23 AM
#4
Re: How to get control Backcolor and store as OLE_COLOR
You have a problem.
The problem is the Label itself.
This is a very easy task to accomplish with a control that has an hWnd property. Labels do not have this property.
I would suggest moving to a textbox, which does have this property, and making the textbox look like a label. Then you can do this
vb Code:
Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function GetCapture Lib "user32" () As Long
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, _
Y As Single)
If (X Or Y) < 0 Or (X > Text1.Width) Or (Y > Text1.Height) Then
ReleaseCapture
Text1.BackColor = vbBlue
ElseIf GetCapture() <> Text1.hWnd Then
SetCapture Text1.hWnd
Text1.BackColor = vbRed
End If
End Sub
-
Nov 28th, 2007, 08:03 AM
#5
Thread Starter
Hyperactive Member
Re: How to get control Backcolor and store as OLE_COLOR
It is work well if i used colorconstants. But it can't work if i get color from label.backcolor..
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Nov 28th, 2007, 08:08 AM
#6
Thread Starter
Hyperactive Member
Re: How to get control Backcolor and store as OLE_COLOR
vb Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Label Then
If ctrl.BackColor = &HC0C0FF Then
ctrl.BackColor = vbRed
End If
End If
Next
End Sub
Private Sub lblMachine_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If lblMachine.Item(Index).BackColor = vbRed Then
Me.lblMachine.Item(Index).BackColor = &HC0C0FF
End If
End Sub
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Nov 28th, 2007, 08:12 AM
#7
Re: How to get control Backcolor and store as OLE_COLOR
You'd have to look for GetSysColor API and pass the color values that appear as negative through it, but without the negative indigator ie. without highest bit set (sounds complex?). Code would be basically like this:
Code:
If ColorValue < 0 Then
RealColorValue = GetSysColor(ColorValue And &HFF&)
Else
RealColorValue = ColorValue
End If
For a very easy solution, see UniLabel and you don't need to wonder. It has MouseEnter and MouseLeave events that allow you to change background and forecolor easily. It also has padding properties so you can have some more space around the text.
You can also find a lot of small info and help for making your own user control from that control.
-
Nov 28th, 2007, 08:16 AM
#8
Thread Starter
Hyperactive Member
Re: How to get control Backcolor and store as OLE_COLOR
Thanks Merri and Hack provided me so many solution.
I will try the example provided by Merri.
If i still got any problem i will try to ask again here
Thanks ..
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Nov 28th, 2007, 08:20 AM
#9
Re: How to get control Backcolor and store as OLE_COLOR
 Originally Posted by nUflAvOrS
It is work well if i used colorconstants. But it can't work if i get color from label.backcolor..
I don't understand this.
If this is your program, your form, and your label/textbox, won't you already know what the backcolor is?
-
Nov 28th, 2007, 08:26 AM
#10
Thread Starter
Hyperactive Member
Re: How to get control Backcolor and store as OLE_COLOR
It work if i use above code
vb Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Label Then
If ctrl.BackColor = &HC0C0FF Then
ctrl.BackColor = vbRed
End If
End If
Next
End Sub
Private Sub lblMachine_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If lblMachine.Item(Index).BackColor = vbRed Then
Me.lblMachine.Item(Index).BackColor = &HC0C0FF
End If
End Sub
But now i need change my backcolor of the Label to Previous color i have to declare a private variable to store the LastColor ( Previous Color )
The Lastcolor is Label.BackColor
This code is work when debugging but when run-time it work with not stable.
Seem sometime the LastColor cannot store the Backcolor.
VB Code:
Private lastColor as OLE_COLOR
vb Code:
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Label Then
If ctrl.BackColor = &HC0C0FF Then
ctrl.BackColor = LastColor
End If
End If
Next
End Sub
Private Sub lblMachine_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
If lblMachine.Item(Index).BackColor = vbRed Then
LastColor = Me.lblMachine.Item(Index).BackColor
Me.lblMachine.Item(Index).BackColor = &HC0C0FF
End If
End Sub
Last edited by nUflAvOrS; Nov 28th, 2007 at 08:33 AM.
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
-
Nov 28th, 2007, 08:04 PM
#11
Thread Starter
Hyperactive Member
Re: How to get control Backcolor and store as OLE_COLOR
Very hard to describe my problem, I found that my problem is when on mousemove event the LastColor should store the Last change color before the new color, but the mousemove event Is working as long as I'm moving the mouse cursor on the LABEL. Thus, the Lastcolor will immediately retrieve the color value from Origin Color back to mousemoved color.
So when i mouseover the Label the color will be mousemove color. Basically, It will change the color back to ORIGIN color if my cursor Leave the Label area. However, It would not. It will remain in Mousemoved Color..
Where there is no hope, there can be no endeavor.
There are two ways of rising in the world, either by your own industry or by the folly of others.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|