|
-
May 7th, 2005, 06:09 PM
#1
Thread Starter
Lively Member
[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.
-
May 7th, 2005, 06:12 PM
#2
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.
-
May 7th, 2005, 06:13 PM
#3
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 7th, 2005, 06:19 PM
#4
Thread Starter
Lively Member
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
-
May 7th, 2005, 06:22 PM
#5
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 7th, 2005, 06:27 PM
#6
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 7th, 2005, 06:31 PM
#7
Thread Starter
Lively Member
Re: Make VB act as button...
How would i find the required position of the top left of the form on load..?
-
May 7th, 2005, 06:33 PM
#8
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 Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API 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 
-
May 7th, 2005, 06:43 PM
#9
Thread Starter
Lively Member
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
-
May 7th, 2005, 07:10 PM
#10
Re: Make VB act as button...
That will give you the .top and .left coordinates. Try it!
-
May 7th, 2005, 07:33 PM
#11
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)?
-
May 7th, 2005, 07:50 PM
#12
Thread Starter
Lively Member
Re: Make VB act as button...
Whatever i do the cursor starts at the top left of the monitor not the form..?
-
May 7th, 2005, 07:55 PM
#13
Re: Make VB act as button...
If your image is called Image1, just use this:
VB Code:
Option Explicit
Private Sub Form_Load()
Image1_Click
End Sub
Private Sub Image1_Click()
Beep
End Sub
and your image will be clicked.
-
May 7th, 2005, 07:57 PM
#14
Registered User
Re: Make VB act as button...
if your app = true then
use Image1_Click(),
else
use the api
endif
-
May 7th, 2005, 08:20 PM
#15
Thread Starter
Lively Member
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
-
May 7th, 2005, 08:38 PM
#16
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...
-
May 7th, 2005, 08:40 PM
#17
Thread Starter
Lively Member
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:
Public Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Me.MousePointer = 99
Me.MouseIcon = Picture1.Picture
Picture1.Visible = False
End Sub
Public Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim mousexy As PointAPI
GetCursorPos mousexy
SelWnd = WindowFromPoint(mousexy.X, mousexy.Y)
Me.MousePointer = 0
Picture1.Visible = True
End Sub
Private Sub form_load()
Picture1_Click
End Sub
Last edited by BefunMunkToloGen; May 7th, 2005 at 08:46 PM.
-
May 7th, 2005, 08:45 PM
#18
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?
-
May 7th, 2005, 08:47 PM
#19
Thread Starter
Lively Member
Re: Make VB act as button...
It's my own form, my own app. The picture box is always there, same place..
-
May 7th, 2005, 08:51 PM
#20
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
-
May 7th, 2005, 08:54 PM
#21
Re: Make VB act as button...
If it is a Picture Box and not an Image control then use this code:
VB Code:
Private Declare Function SetCursorPos Lib "user32.dll" ( _
ByVal x As Long, _
ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByRef lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Form_Load()
Dim r As RECT
'Show the Form so the picture box is visible
Me.Show
Call GetWindowRect(Picture1.hWnd, r)
Call SetCursorPos(r.Left, r.Top)
End Sub
-
May 7th, 2005, 08:55 PM
#22
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|