473,804 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to detect mouseclick anywhere

Hello!

How to detect mouseclick anywhere on the form? There is a lot of
controls on the form, so I don't want to add eventhandler for each of them.
How can I do it in another way?

Adam

--
**remove REM from the mail address**
Nov 15 '05 #1
3 6797
In article <eu************ *@TK2MSFTNGP11. phx.gbl>, ku***@Iname.com
says...
Hello!

How to detect mouseclick anywhere on the form? There is a lot of
controls on the form, so I don't want to add eventhandler for each of them.
How can I do it in another way?


See the IMessageFilter interface.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 15 '05 #2
100
Hi Adam,

The only way I can think of is to create message filter and screen off the
mouse messages.

1. Add IMessageFilter interface to the list of interfaces implemented by the
form
public class MyForm: Form, IMessageFilter
{
.....
}

2. In form constructor add the following line

Application.Add MessageFilter(t his);

3. Implement the IMessageFilter' s only member in the form's class
Something like

public bool PreFilterMessag e(ref Message m)
{
Control ctrl = Control.FromHan dle(m.HWnd);

if(ctrl != null && (ctrl == this || this.Contains(c trl))))
{
switch(m.Msg)
{
case 0x0201: //0x0201 is the constant value for
WM_LBUTTONDOWN. For more constants see winuser.h
///Do something when the left-mouse button is down
break
case .....
break
}
}
return false;
}
HTH
B\rgds
100

"Kubik" <ku***@Iname.co m> wrote in message
news:eu******** *****@TK2MSFTNG P11.phx.gbl...
Hello!

How to detect mouseclick anywhere on the form? There is a lot of
controls on the form, so I don't want to add eventhandler for each of them. How can I do it in another way?

Adam

--
**remove REM from the mail address**

Nov 15 '05 #3
The only way I can think of is to create message filter and screen off the
mouse messages.

Thanks a lot, it works great! :)

--
Adam
**remove REM from the mail address**
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
9265
by: Cam | last post by:
Hi to all I have searched this subject and found some posts but none of them seem to answer my problem. I am developing a shop site and need to detect when a session times out through inactivity and tell the user that it has been reset and he has to start over. I set some session variables in a global.asa file so when the user restarts
4
16736
by: Peter Rilling | last post by:
What is the difference between the MouseClick and Click events?
2
1728
by: Rich | last post by:
Hello, I need to trap/detect when a textbox is entered via the tabkey. If the textbox is not empty when entered via the tabkey then set focus to next textbox. To enter that textbox would then require a mouseclick if it already contains text to be edited. I am guessing that I would need to trap for this in the Enter Event of this particular textbox. I tried this in the Enter Event of the Textbox, but...
4
6444
by: Chris Dunaway | last post by:
I added a MouseClick event to a Button control. It responds properly to the Left click of the button, but not a middle click or right click. Is it possible to get a right click and/or middle click for a standard Button control?
6
5172
by: Kristian Frost | last post by:
Hi, I'm trying to add, as you might guess, mouseclick listeners to the shapes I am drawing using the GDI+ commands in a similar sort of way as could be done with the old VB "shapes". Problem is, I'm really not sure of the best way to go about it. I was hoping I could do it directly like the old shape_onclick events, but that doesn't seem to be available for GDIs so maybe I could hack something together using collections of GDI objects and...
2
1403
by: GS | last post by:
how can I tell if it is right mouse click from left mouseclick? I would also to test if a key like control is being held down at the same time. what I would really like to is to capture control right mouse click for debugging purpose. in a generic event handler.
6
1925
by: RolltheBall | last post by:
Hi there. I am trying to make a certain symbol to appear upon every mouseclick. However, the symbol is a cross and an arrow head. This is how I tried to do it. Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _ System.Windows.Forms.PaintEventArgs) Handles _ MyBase.Paint Dim bluePen As New Pen(Color.Blue, 1.5)
6
2242
by: Steve | last post by:
Hi All I have an on-screen keyboard within a POS program I have written in VB.net 2005, for touch screen computers I have it set to 'always on top' so the user can move the cursor to different text boxes and type using the on-screen keyboard The keyboard launches via the mouseclick event for any text box If another form is launched, with the onscreen keyboard still visible, the
0
1183
by: Ryan Liu | last post by:
I have a DataGrid with only one column is editable. It is a DataGridViewCheckBoxColumn. I want to detect if the any checkbox state is changed. So I listen to ColumnChanged event. But whenever user click the checkbox, and checkbox state changed, but the event is not fired until the user click anywhere else in the grid or in the parent form.
0
9594
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10343
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10089
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9171
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7634
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5530
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4308
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.