473,414 Members | 1,988 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,414 software developers and data experts.

Waiting for a Mouse click

Hi all,

I need to wait for the user to click the mouse:

// some code before
WaitForMouseClick();// Wait until the user clicks the mouse
// go on doing something

Under Win32 using C++, you could poll the mouse buttons states. Is this
possible using C# and .NET?

Thanks in advance,
Andy
Nov 16 '05 #1
4 13178
Hi

You need to use the MouseEventArgs Class. see msdn here
http://msdn.microsoft.com/library/en...WindowsFormsMo
useEventArgsClassTopic.asp
Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
"Andreas Müller" <me@privacy.net> wrote in message
news:c6************@ID-83644.news.uni-berlin.de...
Hi all,

I need to wait for the user to click the mouse:

// some code before
WaitForMouseClick();// Wait until the user clicks the mouse
// go on doing something

Under Win32 using C++, you could poll the mouse buttons states. Is this
possible using C# and .NET?

Thanks in advance,
Andy

Nov 16 '05 #2
Mike Kitchen wrote:
Hi

You need to use the MouseEventArgs Class. see msdn here
http://msdn.microsoft.com/library/en...WindowsFormsMo useEventArgsClassTopic.asp
Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
"Andreas Müller" <me@privacy.net> wrote in message
news:c6************@ID-83644.news.uni-berlin.de...
Hi all,

I need to wait for the user to click the mouse:

// some code before
WaitForMouseClick();// Wait until the user clicks the mouse
// go on doing something

Under Win32 using C++, you could poll the mouse buttons states. Is
this possible using C# and .NET?

Thanks in advance,
Andy


Hi Mike,

thanks for the answer, however that was not what I was looking for :-(. I
propably explained it bad.

The normal way in a win form application to capture the mouse is to react to
the mouse events, such as MouseDown using the MouseEventArgs class .

However, I have the (strange? ;-) ) need to do something like this

class Xox
{
public static AquirePointFromUser()
{
// promt the user
MessageBox.Show("Please pick a point");

// now wait *here* for the pick of the user
WaitForMouseClick();

// get the currrent position
return Control.MousePosition;
}
private static WaitForMouseClick()
{
// see below
}
}

I need this for an API of my application. When a client calls
Xox.AquirePointFromUser(), it has to be made sure, that the user really
clicks and that the client can't go on untill it happened.

The idea of the API function is, that when called, the user is prompted to
select something and after that the function returns. So I want to wait for
the mouse to be clicked. What I mean by waiting, is that WaitForMouseClick()
wil not return *before* the mouse was clicked.

In Pseudo code, WaitForMouseClick() would look like this

private static void WaitForMouseClick()
{
while(true)
{
bool bMouseDown = Poll_Mouse_State_Button();//<-this is what
//
im looking for
if(bMouseDown)
return;
}
}

I can do this in Win32, so I guess it can be don using C#, too.

I hope this explains it a bit better.

Cheers,
Andy
Nov 16 '05 #3
> Hi Mike,

thanks for the answer, however that was not what I was looking for :-(. I
propably explained it bad.

The normal way in a win form application to capture the mouse is to react to the mouse events, such as MouseDown using the MouseEventArgs class .

However, I have the (strange? ;-) ) need to do something like this

class Xox
{
public static AquirePointFromUser()
{
// promt the user
MessageBox.Show("Please pick a point");

// now wait *here* for the pick of the user
WaitForMouseClick();

// get the currrent position
return Control.MousePosition;
}
private static WaitForMouseClick()
{
// see below
}
}

I need this for an API of my application. When a client calls
Xox.AquirePointFromUser(), it has to be made sure, that the user really
clicks and that the client can't go on untill it happened.

The idea of the API function is, that when called, the user is prompted to
select something and after that the function returns. So I want to wait for the mouse to be clicked. What I mean by waiting, is that WaitForMouseClick() wil not return *before* the mouse was clicked.

In Pseudo code, WaitForMouseClick() would look like this

private static void WaitForMouseClick()
{
while(true)
{
bool bMouseDown = Poll_Mouse_State_Button();//<-this is what
//
im looking for
if(bMouseDown)
return;
}
}

I can do this in Win32, so I guess it can be don using C#, too.

I hope this explains it a bit better.

Cheers,
Andy

What you can do is set a state :

class Toto
{
private int state = 0;

//when the user do the condition that blocks, set state to 1

private void onclick(good param)
{
if (state == 1)
do my stufff
else
do my other stuff
}

}

And, if inside the rest of the code you have things that must not be used if
it is not validated, you can do a if (state == 1) then not good.

Might not be clear and perhaps not what you want, nevertheless, I hop it
helps you :o)
Nov 16 '05 #4
Mathieu Chavoutier wrote:
Hi Mike,

thanks for the answer, however that was not what I was looking for
:-(. I propably explained it bad.

The normal way in a win form application to capture the mouse is to
react to the mouse events, such as MouseDown using the
MouseEventArgs class .

However, I have the (strange? ;-) ) need to do something like this

class Xox
{
public static AquirePointFromUser()
{
// promt the user
MessageBox.Show("Please pick a point");

// now wait *here* for the pick of the user
WaitForMouseClick();

// get the currrent position
return Control.MousePosition;
}
private static WaitForMouseClick()
{
// see below
}
}

I need this for an API of my application. When a client calls
Xox.AquirePointFromUser(), it has to be made sure, that the user
really clicks and that the client can't go on untill it happened.

The idea of the API function is, that when called, the user is
prompted to select something and after that the function returns. So
I want to wait for the mouse to be clicked. What I mean by waiting,
is that WaitForMouseClick() wil not return *before* the mouse was
clicked.

In Pseudo code, WaitForMouseClick() would look like this

private static void WaitForMouseClick()
{
while(true)
{
bool bMouseDown = Poll_Mouse_State_Button();//<-this is what

// im looking for
if(bMouseDown)
return;
}
}

I can do this in Win32, so I guess it can be don using C#, too.

I hope this explains it a bit better.

Cheers,
Andy

What you can do is set a state :

class Toto
{
private int state = 0;

//when the user do the condition that blocks, set state to 1

private void onclick(good param)
{
if (state == 1)
do my stufff
else
do my other stuff
}

}

And, if inside the rest of the code you have things that must not be
used if it is not validated, you can do a if (state == 1) then not
good.

Might not be clear and perhaps not what you want, nevertheless, I hop
it helps you :o)


It did not :o(, but thank you anyway.

Basically it's the first step. The problem is, that I have to *wait* for the
state to change:
class Toto
{
private int state = 0;
private void OnMouseClick(good param)
{
state = 1;//change the state
}
public Point Pick()
{

// need to wait untill the state changes
while(state == 0)
{
//this will eat all CPU power and block
//my thread, so I never get the MouseClick event.
//Thread.Sleep(10);// Does not help either
}
}
}
Nov 16 '05 #5

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

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...
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...
2
by: tommyny04 | last post by:
Really need help with this one. I'm writing a program to simulate a Risk game and I need to write a method to make two countries neighbors, which would be done by adding each the neighbor country to...
10
by: Sebouh | last post by:
Hi guys. I don't know how to implement this so i was hoping if any of you can help me. I have a code like this one: public static void main (String args) { //create frame and button ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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.