Results 1 to 22 of 22

Thread: [SOLVED]Make VB act as button...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Resolved [SOLVED]Make VB act as button...

    Hi, is it possible so that when my VB form opens it mouseup and mousedown are automatically done without the user using the mouse? I need the click to be in the top left of the form if it's possible...

    Thanks
    Last edited by BefunMunkToloGen; May 7th, 2005 at 08:56 PM.

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

    Re: Make VB act as button...

    Are you clicking on a certain control? You can call a click event thru code, or use an API to click anywhere on the screen.

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

    Re: Make VB act as button...

    What are you trying to do in your app? Invoke the system menu in the control box?
    You can drop down the system menu using some APIs if that what your trying to do.
    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

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    Im trying to click an image in the top left of the screen. I don't know what would be a good phrase or keywords to search for some code though.

    Cheers

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

    Re: Make VB act as button...

    Is this in your app or another program?
    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

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

    Re: Make VB act as button...

    You can use the SetCursorPos API to move the mouse to the screen coordinates you desire.

    SetCursorPos
    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

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    How would i find the required position of the top left of the form on load..?

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

    Re: Make VB act as button...

    Your form? Form1.Left & Form1.Top ???
    If you need another programs positioning then you need to use FindWindow API.
    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
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    What i mean is this:

    SetCursorPos (frmMain.Top), (frmMain.Left)

    How do i find the X,Y position of frmMain.Left and frmMain.Top on form_load?

    Thanks so far Im getting there

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

    Re: Make VB act as button...

    That will give you the .top and .left coordinates. Try it!

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Make VB act as button...

    Well SetCursorPos requires the X and Y coordinates to be in pixels and the Top and Left properties of a Form will always return them in Twips so you need to divide them with Screen.TwipsPerPixelX and Screen.TwipsPerPixelX.

    But if this is your programs form why not just call the Image1_Click event procedure (if Image1 is the name of your image)?

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    Whatever i do the cursor starts at the top left of the monitor not the form..?

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

    Re: Make VB act as button...

    If your image is called Image1, just use this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  Image1_Click
    5. End Sub
    6.  
    7. Private Sub Image1_Click()
    8.   Beep
    9. End Sub

    and your image will be clicked.

  14. #14
    Registered User HellRaider's Avatar
    Join Date
    Sep 2003
    Posts
    70

    Re: Make VB act as button...

    if your app = true then
    use Image1_Click(),
    else
    use the api
    endif

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    I'm not trying to do image_click... I want VB to click on the image for me, so that MouseDown and MouseUp are used...The clicking isn't the problem, just starting the mouse in the top left hand side of the form.

    Thanks

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

    Re: Make VB act as button...

    Mouse Down and Mouse up is the same thing as a click, and that's what will execute if you execute mouse down and mouse up. You can click on the form, if that's what you want using the Form_Click event.

    What exactly are you trying to do? Perhaps I am misubderstanding...

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    I'm trying to take a screenie of an object. If i click the image whilst the programme is running it works, if i use image1_click it doesn't.

    VB Code:
    1. Public Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2. Me.MousePointer = 99
    3. Me.MouseIcon = Picture1.Picture
    4. Picture1.Visible = False
    5. End Sub
    6.  
    7. Public Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
    8. Dim mousexy As PointAPI
    9. GetCursorPos mousexy
    10. SelWnd = WindowFromPoint(mousexy.X, mousexy.Y)
    11. Me.MousePointer = 0
    12. Picture1.Visible = True
    13. End Sub
    14. Private Sub form_load()
    15. Picture1_Click
    16. End Sub
    Last edited by BefunMunkToloGen; May 7th, 2005 at 08:46 PM.

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

    Re: Make VB act as button...

    You could use SPY++ to get a handle to the object that you want to click.
    Is it your own app? Is it always the same app? Same object?

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    It's my own form, my own app. The picture box is always there, same place..

  20. #20
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Make VB act as button...

    try this, just adjust to get exactly where you want

    SetCursorPos Me.Left / Screen.TwipsPerPixelX + 10, Me.top / Screen.TwipsPerPixelY + 100

    pete

  21. #21
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Make VB act as button...

    If it is a Picture Box and not an Image control then use this code:
    VB Code:
    1. Private Declare Function SetCursorPos Lib "user32.dll" ( _
    2.  ByVal x As Long, _
    3.  ByVal y As Long) As Long
    4.  
    5. Private Declare Function GetWindowRect Lib "user32.dll" ( _
    6.  ByVal hwnd As Long, _
    7.  ByRef lpRect As RECT) As Long
    8.  
    9. Private Type RECT
    10.     Left As Long
    11.     Top As Long
    12.     Right As Long
    13.     Bottom As Long
    14. End Type
    15.  
    16. Private Sub Form_Load()
    17.     Dim r As RECT
    18.     'Show the Form so the picture box is visible
    19.     Me.Show
    20.     Call GetWindowRect(Picture1.hWnd, r)
    21.     Call SetCursorPos(r.Left, r.Top)
    22. End Sub

  22. #22

    Thread Starter
    Lively Member
    Join Date
    Feb 2005
    Posts
    107

    Re: Make VB act as button...

    Sorted! Thanks everyone

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