Detecting mouse hold in custom control

S

Seefor

I have a custom control which has a ContextMenu property like so:

public class MyControl : Control
{
ContextMenu _contextMenu;

public ContextMenu Menu
{
get { return _contextMenu; }
set { _contextMenu = value; }
}

I want to display this context menu when the user holds the mouse button
down on my control for a while (like a ListBox context menu would work).

How can I detect when the user has held down the mouse so that I can call
the ContextMenu's Show method, and how can I make that lovely red circle
appear on the PDA when they do?

TIA
 
S

Seefor

S

Seefor

How can I get the HWND of the current form that the control is running on?
I've seen this code, but there has to be a nicer way - and how would I set
the text of the form that the control is running on?

[DllImport("coredll.dll"]
public static extern IntPtr GetCapture();

[DllImport("coredll.dll")]
public static extern IntPtr FindWindow(String lpClassName, String
lpWindowName);

this.Text = "FindMe";
IntPtr hwnd1 = FindWindow(null, "FindMe");

this.Capture = true;
IntPtr hwnd2 = GetCapture();
this.Capture = false;
 
D

Daniel Moth

Please start new threads for new questions.

You can set the text of any control (inc. Forms) via the Text property.

For getting the Handle with NETCF 1.0 there are a number of approaches and
you have shown two (that are mutually exclusive):
1. The GetCapture
2. FindWindow

If you can use the first approach, it is preferable.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Seefor said:
How can I get the HWND of the current form that the control is running on?
I've seen this code, but there has to be a nicer way - and how would I set
the text of the form that the control is running on?

[DllImport("coredll.dll"]
public static extern IntPtr GetCapture();

[DllImport("coredll.dll")]
public static extern IntPtr FindWindow(String lpClassName, String
lpWindowName);

this.Text = "FindMe";
IntPtr hwnd1 = FindWindow(null, "FindMe");

this.Capture = true;
IntPtr hwnd2 = GetCapture();
this.Capture = false;


Seefor said:
 
S

Seefor

Sorry, this was a related question (or at least I hope it is) - I need the
handle of the form my custom control is running on in order to call
SHRecognizeGesture. My question was how can I get the handle for the form
that the control is running on, from within the custom control code itself?

Daniel Moth said:
Please start new threads for new questions.

You can set the text of any control (inc. Forms) via the Text property.

For getting the Handle with NETCF 1.0 there are a number of approaches and
you have shown two (that are mutually exclusive):
1. The GetCapture
2. FindWindow

If you can use the first approach, it is preferable.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Seefor said:
How can I get the HWND of the current form that the control is running
on?
I've seen this code, but there has to be a nicer way - and how would I
set the text of the form that the control is running on?

[DllImport("coredll.dll"]
public static extern IntPtr GetCapture();

[DllImport("coredll.dll")]
public static extern IntPtr FindWindow(String lpClassName, String
lpWindowName);

this.Text = "FindMe";
IntPtr hwnd1 = FindWindow(null, "FindMe");

this.Capture = true;
IntPtr hwnd2 = GetCapture();
this.Capture = false;


Seefor said:
thanks!

Override OnMouseDown (or handle the MouseDown event) to detect the user
action (coupled with MouseUp). Use ContextMenu.Show to sow the
contextmenu. Use SHRecognizeGesture for the red dotted circle

http://msdn.microsoft.com/library/d...mwindowsformscontrolclassonmousedowntopic.asp

http://www.danielmoth.com/Blog/2004/11/contextmenushow.html

http://groups-beta.google.com/group...tframework/search?q=shrecognizegesture&hl=en&

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


I have a custom control which has a ContextMenu property like so:

public class MyControl : Control
{
ContextMenu _contextMenu;

public ContextMenu Menu
{
get { return _contextMenu; }
set { _contextMenu = value; }
}

I want to display this context menu when the user holds the mouse
button down on my control for a while (like a ListBox context menu
would work).

How can I detect when the user has held down the mouse so that I can
call the ContextMenu's Show method, and how can I make that lovely red
circle appear on the PDA when they do?

TIA
 
D

Daniel Moth

Be creative... get the handle in the form when it is shown and then pass it
to the control.. or use in the control the Parent property to get to the
form.. something like that..

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Seefor said:
Sorry, this was a related question (or at least I hope it is) - I need the
handle of the form my custom control is running on in order to call
SHRecognizeGesture. My question was how can I get the handle for the form
that the control is running on, from within the custom control code
itself?

Daniel Moth said:
Please start new threads for new questions.

You can set the text of any control (inc. Forms) via the Text property.

For getting the Handle with NETCF 1.0 there are a number of approaches
and you have shown two (that are mutually exclusive):
1. The GetCapture
2. FindWindow

If you can use the first approach, it is preferable.

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


Seefor said:
How can I get the HWND of the current form that the control is running
on?
I've seen this code, but there has to be a nicer way - and how would I
set the text of the form that the control is running on?

[DllImport("coredll.dll"]
public static extern IntPtr GetCapture();

[DllImport("coredll.dll")]
public static extern IntPtr FindWindow(String lpClassName, String
lpWindowName);

this.Text = "FindMe";
IntPtr hwnd1 = FindWindow(null, "FindMe");

this.Capture = true;
IntPtr hwnd2 = GetCapture();
this.Capture = false;


thanks!

Override OnMouseDown (or handle the MouseDown event) to detect the
user action (coupled with MouseUp). Use ContextMenu.Show to sow the
contextmenu. Use SHRecognizeGesture for the red dotted circle

http://msdn.microsoft.com/library/d...mwindowsformscontrolclassonmousedowntopic.asp

http://www.danielmoth.com/Blog/2004/11/contextmenushow.html

http://groups-beta.google.com/group...tframework/search?q=shrecognizegesture&hl=en&

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


I have a custom control which has a ContextMenu property like so:

public class MyControl : Control
{
ContextMenu _contextMenu;

public ContextMenu Menu
{
get { return _contextMenu; }
set { _contextMenu = value; }
}

I want to display this context menu when the user holds the mouse
button down on my control for a while (like a ListBox context menu
would work).

How can I detect when the user has held down the mouse so that I can
call the ContextMenu's Show method, and how can I make that lovely
red circle appear on the PDA when they do?

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top