F
Frankenstein
Hi,
I need to catch the mouse click event wherever it occurs in the form,
irrespective on which control the mouse/stylus is clicked. I tried using
the ApplicationEx.AddMessageFilter() API from the OpenNetCF library.
However, the API does not seem to work as suggested on the site. Even the
ApplicationEx sample from the site did not run on my PocketPC emulator.
Can you please take a look at the code pasted below and tell me where I am
going wrong. Apologies, if the formatting goes astray in the post.
Regards.
------
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.IO;
using OpenNETCF.Windows.Forms;
using Microsoft.WindowsCE.Forms;
namespace Learn
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.MainMenu mainMenu1;
public Form1()
{
InitializeComponent();
ApplicationEx.AddMessageFilter(new MouseFilter());
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.comboBox1.Items.Add("One");
this.comboBox1.Items.Add("Two");
this.comboBox1.Items.Add("Three");
this.comboBox1.Location = new System.Drawing.Point(24, 48);
this.button1.Location = new System.Drawing.Point(160, 128);
this.button1.Text = "button1";
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
}
class MouseFilter : IMessageFilter
{
public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message msg)
{
switch((WinMsg)msg.Msg)
{
case WinMsg.WM_LBUTTONDOWN:
System.Windows.Forms.MessageBox.Show("Double Click!");
break;
}
return false;
}
}
}
---
I need to catch the mouse click event wherever it occurs in the form,
irrespective on which control the mouse/stylus is clicked. I tried using
the ApplicationEx.AddMessageFilter() API from the OpenNetCF library.
However, the API does not seem to work as suggested on the site. Even the
ApplicationEx sample from the site did not run on my PocketPC emulator.
Can you please take a look at the code pasted below and tell me where I am
going wrong. Apologies, if the formatting goes astray in the post.
Regards.
------
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;
using System.IO;
using OpenNETCF.Windows.Forms;
using Microsoft.WindowsCE.Forms;
namespace Learn
{
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.MainMenu mainMenu1;
public Form1()
{
InitializeComponent();
ApplicationEx.AddMessageFilter(new MouseFilter());
}
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button();
this.comboBox1.Items.Add("One");
this.comboBox1.Items.Add("Two");
this.comboBox1.Items.Add("Three");
this.comboBox1.Location = new System.Drawing.Point(24, 48);
this.button1.Location = new System.Drawing.Point(160, 128);
this.button1.Text = "button1";
this.Controls.Add(this.button1);
this.Controls.Add(this.comboBox1);
this.Menu = this.mainMenu1;
this.Text = "Form1";
}
#endregion
static void Main()
{
Application.Run(new Form1());
}
}
class MouseFilter : IMessageFilter
{
public bool PreFilterMessage(ref Microsoft.WindowsCE.Forms.Message msg)
{
switch((WinMsg)msg.Msg)
{
case WinMsg.WM_LBUTTONDOWN:
System.Windows.Forms.MessageBox.Show("Double Click!");
break;
}
return false;
}
}
}
---