Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Flat Button Control

Status
Not open for further replies.

MrVB50au

Programmer
Mar 16, 2003
326
AU
Hiya All,

I know that there are a lot of buttons, even flat buttons on the market and internet today, but I'm creating my own special Flat button but would like an answer to a very simple question, I know it can be done but I just don't know how to go about it and would love some suggestion.

HERE'S MY PROBLEM:
When I glide my mouse over my button the outline appears as it should however I want the control to recognize when the mouse isn't no longer over the button to put it back to the flat mode.

I know this can be done by setting the surroundings MouseMove event to set it to flat mode, but I want to have the control 'ITSELF' to recognize that the mouse isn't no longer on the control.

Any ideas would be greatfully appriciated.

Andrew G.
 
here is some code that strongm posted a few days ago, i cant remember the thread or the subject of the thread, but i swiped the code. it doesnt do exactly what you want (ie the border bit) but it does demonstrate the idea
Code:
Option Explicit

Private Declare Function SetCapture Lib "user32" ( _
    ByVal hWnd As Long _
) As Long

Private Declare Function WindowFromPoint Lib "user32" ( _
    ByVal xPoint As Long, _
    ByVal yPoint As Long _
) As Long

Private Declare Function GetCursorPos Lib "user32" ( _
    lpPoint As POINTAPI _
) As Long

Private Declare Function ReleaseCapture Lib "user32" () As Long

Private Type POINTAPI
        X As Long
        Y As Long
End Type

Private Enum RollType
    RollIn = 1
    RollOut = 2
End Enum

Private Function RollOver(ctlControl As Control) As RollType
    Dim myPoint As POINTAPI
    Dim OverWindow As Boolean
    
    GetCursorPos myPoint
    On Error Resume Next ' Bit of a cheat to handle case where control does not have an hWnd
    OverWindow = (ctlControl.hWnd = WindowFromPoint(myPoint.X, myPoint.Y))
    On Error GoTo 0

    If OverWindow Then
        SetCapture ctlControl.hWnd
        RollOver = RollIn
    Else
        ReleaseCapture
        RollOver = RollOut
    End If
    
End Function

Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If RollOver(Command1) = RollIn Then
        'Do rollin event, eg:
        Command1.BackColor = &H80000010 ' Assumes button style is Graphical
    Else ' Ok, we've got a rollout
        ' Do rollout event, eg:
        Command1.BackColor = &H8000000F ' Assumes button style is Graphical
    End If
End Sub

Private Sub Command2_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If RollOver(Command2) = RollIn Then
        'Do rollin event, eg:
'        Command2.Picture = LoadPicture("image1.jpg") ' Assumes button style is Graphical
    Else ' Ok, we've got a rollout
        ' Do rollout event, eg:
'        Command2.Picture = LoadPicture("image2.jpg") ' Assumes button style is Graphical
    End If
End Sub
hope this is some help!

If somethings hard to do, its not worth doing - Homer Simpson
------------------------------------------------------------------------
A General Guide To Excel in VB FAQ222-3383
File Formats Galore @
 
Maybe you could take a look at the code on this link:
It's from the Planet-Source-Code site by a programmer called LaVolpe. I use it in my apps and I'm very satisfied with it. You don't have to use it but you could check out his code and maybe find what you need to know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top