473,406 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Force Mouse Click

devonknows
137 100+
Hey all, long time no see :), erm what it is i have a DirListBox Control on my form and i need to make the mouse left click before showing the popup menu, so the item that the user has right clicked on is highlighted before showing the popup menu, or if there is a better way of doing this then forcing the mouse to click before using the PopupMenu Method, for example the x and y of the mouse ... any help would be greatly appreciated.

Kind Regards as Always,
Devon.
May 4 '07 #1
8 10766
Killer42
8,435 Expert 8TB
Hey all, long time no see :), erm what it is i have a DirListBox Control on my form and i need to make the mouse left click before showing the popup menu, so the item that the user has right clicked on is highlighted before showing the popup menu, or if there is a better way of doing this then forcing the mouse to click before using the PopupMenu Method, for example the x and y of the mouse ... any help would be greatly appreciated.

Kind Regards as Always,
Devon.
Although I forget the name, there certainly are API calls to translate mouse x/y coordinates to other things, such as the control which was clicked. Not sure though how you would determine what entry you were positioned over in the list.

I have a sneaking suspicion that you may end up having to make your own equivalent of the dirlistbox, or obtain another control from somewhere. However, in browsing the properties for the DirListBox, I see TopIndex, which sounds as though it may be helpful in your endeavour, in conjunction with the aforementioned mouse coordinates.
May 5 '07 #2
i know how to move the mouse it is like this:

cursor.position = new point(150,150)

i am also looking for how to force a mouse click event

i cant find any code either. thx
Feb 1 '08 #3
Killer42
8,435 Expert 8TB
i know how to move the mouse it is like this:

cursor.position = new point(150,150)

i am also looking for how to force a mouse click event
Thanks vincey92.

What version of VB is that? It must be later than VB6, because (AFAIK) there's no Cursor object in that version.

Sending a mouse click would be done using the SendMessage API call(s), I expect.
Feb 2 '08 #4
devonknows
137 100+
Hi, i did actually find the solution for this, sorry i should have reposted it, But VB6 does not have the Cursor.Posiotion, im assuming VB.Net?, if you can convert it this is what i have for vb6

Place the following Code into a Module.

Expand|Select|Wrap|Line Numbers
  1. 'Module
  2. Option Explicit
  3. Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dX As Long, ByVal dY As Long, _
  4.                                                     ByVal cButtons As Long, ByVal dwExtraInfo As Long)
  5.  
  6. Public Sub ForceMouseClick(ByVal dX As Long, ByVal dY As Long)
  7.         Dim mouse_x As Long
  8.         Dim mouse_y As Long
  9.         mouse_x = CLng(dX * 65535 / Screen.Width)
  10.         mouse_y = CLng(dY * 65535 / Screen.Height)
  11.         mouse_event _
  12.             MOUSEEVENTF_LEFTDOWN Or _
  13.             MOUSEEVENTF_LEFTUP, _
  14.             mouse_x, mouse_y, 0, 0
  15. End Sub
The Reason i needed this code was so that if someone right clicked on a listbox, it would left click first to highlight the option, and then bring up the popup menu i assigned to it, ill post you the code that i have used minus some things, to give you a better understanding.

The following code goes inside your form (The Following Code Demonstrates Force Click for a listbox called 'lstBrowse')
Expand|Select|Wrap|Line Numbers
  1. Private Sub lstBrowse_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  2.     If Button = 2 Then
  3.         'Use the X & Y from the lstBrowse_MouseDown
  4.         Call ForceMouseClick(X, Y)                  'Force Click
  5.         DoEvents                                    'Just to make sure it clicks
  6.         Me.PopupMenu mnuEdit, , , , mnuEditRecord   'Call The Popup Menu
  7.     End If
  8. End Sub
  9.  
I hope this is of help to you
Kind Regards
Devon
Feb 2 '08 #5
daniel aristidou
491 256MB
Um why not...check that an item is selected....before allowing the popupmenu to show... ie nothing selected..no popupmenu on right click?
Feb 2 '08 #6
devonknows
137 100+
Um why not...check that an item is selected....before allowing the popupmenu to show... ie nothing selected..no popupmenu on right click?
Its more to the fact of if you move the mouse of another item in the list box, whilst an item further up is still select and right click, the popupmenu reacts for the one that you have selected, not the one your are hovering over, so by forcing the mouse to left click first you highlight the the item you are currently hovering over.

Its just to make it easier on the user, i know i get frustrated when i have to click something twice just to get one menu (left click then right click)

Kind Regards
Devon
Feb 2 '08 #7
Killer42
8,435 Expert 8TB
Its just to make it easier on the user, i know i get frustrated when i have to click something twice just to get one menu (left click then right click)
Yes, that sort of thing can be very annoying, and it sounds as though you've got a nice solution there.

Thanks very much for posting it.

(I think it will require very little conversion for VB6. Will try to do as soon as I have a chance, and post the results here for anyone else who comes searching.)
Feb 3 '08 #8
thanx guys im using vb2008 express will that force mouse down stuff still work? i no that the movement of the mouse position still worx cos iv tested that but i still would like 2 no bout hte force mouse clikc
Feb 7 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: punkin | last post by:
I am trying to catch mouse position on the entire screen by dynamically generating mouse click event at every 100 ms. My code only works for IEs but not any Netscape or Gecko-based browsers. The...
3
by: mitsura | last post by:
Hi, I have included a small listing. The test program opens a panel and show a bitmap. What I want is to when the mouse is over the bitmap panel, I want to trap the left mouse click. The...
3
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
5
by: Nick | last post by:
Hey guys, I have 2 events on a windows forms datagrid, the mouse move as well as the double click events. What's happening is that when I double click on a row in the grid, the mouse move event...
2
by: scott_gui | last post by:
I am creating a Windows application: The mouse event <Double-Button-1> has a conflict when the <Button-1> event also has a binding. Double clicks will first perform the single click action. This...
2
by: Gamboz Matteo | last post by:
Hi all, I'm writing a widget that should enable the user to choose some item from a huge list that has a tree structure (~23000 items, node with max children = ~1600 kids (only 3 levels in the...
19
by: wmanzo | last post by:
I have a really professional conspiracy movie site and I use tons of layers and an external scroll bar assembly. I would like to put the various sections into MS Iframes and in order to clean up...
5
by: Adeel | last post by:
Hi group! I'm trying to learn C# on my own... I'd appreciate it very much if someone can help me out here. I have a basic form without any controls on it... I want to catch mouse clicks (both...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.