Results 1 to 24 of 24

Thread: [RESOLVED] How to make a button "Visibly Pressed" when I click a Picture

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Resolved [RESOLVED] How to make a button "Visibly Pressed" when I click a Picture

    I have standard command button with a Picture Object on top of it.

    When I click the button, the button is "PRESSED".

    What I want is when I click on the Picture on top of the button, the button is not "PRESSED" and I want it to be visibly "PRESSED", even though I didnt trigger the command's click event.

    Is that possible??

  2. #2
    Frenzied Member
    Join Date
    May 2003
    Location
    Sydney
    Posts
    1,123

    Re: How to make a button "Visibly Pressed" when I click a Picture

    instead of putting a picture on top of the button, you can set the buttons graphical property to true. this way u can put a picture on the button itself.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    The reason i use picture is that I wanted to align the pic to left and text to right.

  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 make a button "Visibly Pressed" when I click a Picture

    In the click event of the picture box, execute whatever code you need to execute then setfocus to the command button. It should look the same way it looks when it gets pressed.

    Although, for the life of me, I can't figure out why you are bothering to use a command button in the first place if that isn't what is going to be executing any code.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Well, it helps but not really what I expected, I mean not 100% exact as it was "PRESSED".

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Its because of my CodeBank thread on aligning a picture and text on a standard button.

    http://www.vbforums.com/showthread.php?t=323449
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to make a button "Visibly Pressed" when I click a Picture

    You can also use a Checkbox set to Graphical, which appears to be a command button, but has a state for ON and OFF.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Yes, but then you wont get the XP themes applied to it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Yes, I used the code to align the Pic. And I am using check box and set to graphical.

    So, how to make the button "PRESSED" when clicked on the PIC??

    Can you guide me? I need this badly.

    Thanks

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to make a button "Visibly Pressed" when I click a Picture

    I use them in an app, and it changes the foreground color when it is ON.
    Makes it obviou that the state has changed.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    What is STATE ON and OFF?

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button "Visibly Pressed" when I click a Picture

    With a checkbox in graphical state your button will, once clicked, be pressed down but till not popup until you click it again.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Sorry about that. State ON is vbchecked.
    Put a checkbox on your form, and set its style to graphical.
    See this example.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Check1_Click()
    4.   If Check1.Value = vbChecked Then
    5.     Check1.BackColor = vbRed
    6.   Else
    7.     Check1.BackColor = vbBlue
    8.   End If
    9. End Sub

    The button will be grey when you start the app, unless you change the color beforehand, or in the properties.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    So, is there anyway to make the button PRESSED when I click the picture objects?

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button "Visibly Pressed" when I click a Picture

    I reasearched and tested a few things and it may be possible but its going to require subclassing of the button and allot of code. Nothing I would really like to try tonight (tired) to be honest. But in case you want to try this is what to look for.

    The BM_SETSTATE message sets the push state of a button and the WM_PAINT message does the painting of the new style.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Ok Thanks for your help so far..

    I will try it out my self.

  17. #17
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Did you try the option button with the picture on it? It has two states as I've said before. You could even change the picture for each state just as I've changed the backcolor.

  18. #18
    Lively Member
    Join Date
    Sep 2005
    Posts
    82

    Re: How to make a button "Visibly Pressed" when I click a Picture

    I think it's a better way to create a custom control for your need. Creating custom control you need to implement the functionality of the button state liKe "PRESSED" for Mousedown event and "UNPRESSED" for mouseup event. Give it a public touch.

  19. #19
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: How to make a button "Visibly Pressed" when I click a Picture

    The Graphical Checkbox would work fine.

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Dglienna, your missing the point. He doesnt want to use the checkbox in graphical style as it doesnt support XP theming or custome positioning of the image.

    I completely forgot that wokawidget wrote a custom button in his component suite download that has a project called XP Button. It allows you to draw custom shaped buttons with images too.


    http://www.vbforums.com/showthread.php?t=328044
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    In some way , I love check Box set a graphical, which it allows me to change the font color, but when click, the value is true, which does not satisfied me, i need to uncheck that.

    Somehow, Standard button will not allow to change the font color, but at least is a BUTTON.

    How to use BM_SETSTATE?

    Is it something to do with API??

  22. #22
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Yes, it is and its involves a process called subclassing which is a process of intercepting the windows message stream going to the window and acting or reacting to certain messages as they are called and overridding their original actions. Too much code to whip up a quick example.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    How do I declare BM_SETSTATE??

    Should I declare it something like this??

    Public Const BS_vCENTER As Long = &HC00

    And what is &HC00??

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    154

    Re: How to make a button "Visibly Pressed" when I click a Picture

    Here's something I did

    VB Code:
    1. Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
    2.     ByVal hwnd As Long, _
    3.     ByVal wMsg As Long, _
    4.     ByVal wParam As Long, _
    5.     lParam As Any _
    6. ) As Long
    7.  
    8. Private sub Picture1_Click()
    9.    Call pushButton(cmdNew,BM_SETSTATE)
    10. End Sub
    11.  
    12. Public Function pushButton(bttn As CommandButton,style as Long)
    13. Dim ss As Long
    14.  
    15.     ss = SendMessage(bttn.hwnd, style, True, 0)
    16.  
    17. End Function

    But I DO NOT know how to declare BM_SETSTATE

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