Button control Events?

M

Mike Menapace

I have an CF app that requires timing controlled by
Button clicks. I have noticed that the Button_Click event
doesn't fire until the pressure is off the button. I need
the Button to fire when first depressed. I can't get the
Button to fire the MouseDown or other events.
Suggestions?
Thanks.

Regards,

Mike Menapace
 
P

Peter Foot [MVP]

If the Button class doesn't meet your requirements it is surprisingly easy
to write your own control - a class which derives from
System.Windows.Forms.Control. You will need to add your own Paint handler to
draw the controls text and background - although here you are not limited to
simply mimicking a standard Button. You can then setup event handlers for
the MouseUp and MouseDown events separately
CustomControl mycontrol = new CustomControl();

mycontrol.Location = new System.Drawing.Point(0, 0);

mycontrol.Width = 50;

mycontrol.Height = 50;

mycontrol.Text = "Test";

mycontrol.Visible = true;

this.Controls.Add(mycontrol);

mycontrol.MouseDown+=new MouseEventHandler(mycontrol_MouseDown);

mycontrol.MouseUp+=new MouseEventHandler(mycontrol_MouseUp);



In these two methods I then set the code to toggle the form backcolour while
the control was being tapped. Therefore you can setup a timing routine in
your MouseDown event and stop it in your MouseUp. The Quickstarts contain a
sample for creating a custom Button:-

http://samples.gotdotnet.com/quickstart/CompactFramework/doc/picturebutton.aspx

Adding designer support requires some additional work - you may or may not
deem this essential to your project, certainly if you want to re-use the
control it is well worth the effort, Alex has written an article on the
subject here:-

http://www.intelliprog.com/articles/index.html



Peter


--
Peter Foot
Windows Embedded MVP

In The Hand
http://www.inthehand.com
 

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