Results 1 to 11 of 11

Thread: How to get control Backcolor and store as OLE_COLOR

  1. #1

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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?

  3. #3

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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:
    1. Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Long) As Long
    2. Private Declare Function ReleaseCapture Lib "user32" () As Long
    3. Private Declare Function GetCapture Lib "user32" () As Long
    4.  
    5. Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, _
    6.     Y As Single)
    7.     If (X Or Y) < 0 Or (X > Text1.Width) Or (Y > Text1.Height) Then
    8.         ReleaseCapture
    9.         Text1.BackColor = vbBlue
    10.     ElseIf GetCapture() <> Text1.hWnd Then
    11.         SetCapture Text1.hWnd
    12.         Text1.BackColor = vbRed
    13.     End If
    14. End Sub

  5. #5

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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.

  6. #6

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get control Backcolor and store as OLE_COLOR

    vb Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Dim ctrl As Control
    3.         For Each ctrl In Me.Controls
    4.             If TypeOf ctrl Is Label Then
    5.                 If ctrl.BackColor = &HC0C0FF Then
    6.                      ctrl.BackColor = vbRed
    7.                 End If
    8.             End If
    9.         Next
    10. End Sub
    11.  
    12. Private Sub lblMachine_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    13.         If lblMachine.Item(Index).BackColor = vbRed Then
    14.             Me.lblMachine.Item(Index).BackColor = &HC0C0FF
    15.         End If
    16. 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.

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    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.

  8. #8

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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.

  9. #9
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to get control Backcolor and store as OLE_COLOR

    Quote 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?

  10. #10

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    Re: How to get control Backcolor and store as OLE_COLOR

    It work if i use above code

    vb Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Dim ctrl As Control
    3.         For Each ctrl In Me.Controls
    4.             If TypeOf ctrl Is Label Then
    5.                 If ctrl.BackColor = &HC0C0FF Then
    6.                      ctrl.BackColor = vbRed
    7.                 End If
    8.             End If
    9.         Next
    10. End Sub
    11.  
    12. Private Sub lblMachine_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    13.         If lblMachine.Item(Index).BackColor = vbRed Then
    14.             Me.lblMachine.Item(Index).BackColor = &HC0C0FF
    15.         End If
    16. 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:
    1. Private lastColor as OLE_COLOR

    vb Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Dim ctrl As Control
    3.         For Each ctrl In Me.Controls
    4.             If TypeOf ctrl Is Label Then
    5.                 If ctrl.BackColor = &HC0C0FF Then
    6.                      ctrl.BackColor = LastColor
    7.                 End If
    8.             End If
    9.         Next
    10. End Sub
    11.  
    12. Private Sub lblMachine_MouseMove(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
    13.         If lblMachine.Item(Index).BackColor = vbRed Then
    14.             LastColor = Me.lblMachine.Item(Index).BackColor
    15.             Me.lblMachine.Item(Index).BackColor = &HC0C0FF
    16.         End If
    17. 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.

  11. #11

    Thread Starter
    Hyperactive Member nUflAvOrS's Avatar
    Join Date
    Jul 2007
    Location
    Malaysia/ Currently at Singapore
    Posts
    372

    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
  •  



Click Here to Expand Forum to Full Width