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

how to tell how long a button is pressed

I'm writing a little mp3 player shell type thing, and I'm trying to
figure out how to determine how long a button has been pressed.

For example, if a user clicks the left button, the song should be
decremented to the previous one. However, if the user holds the button
down for two seconds, the song would begin rewinding. Further, if the
button is pressed for five seconds, the folder will change to a
previous one.... and so on.

I can't find anywhere that says how to do this. Any suggestions?

Nov 17 '05 #1
3 6934
Joe
I did something similar to this. I created a custom button and used a timer.
I added some additional events to let me know when the time was. I your case
you could have an event fire MouseUp event with the amount of time that
passed since it was clicked.
Something like this:

public delegate void OnElapsedTime(object sender, int elapsedTime)
public event OnElapsedTime ElapsedTime;

MouseDown(object sender, MouseEventArgs e)
{
globalDateTime = DateTime.Now;
}

MouseUpEvent(object sender, MouseEventArgs e)
{
if (ElapsedTime != null)
{
DateTime dt = new DateTime();
TimeSpan ts = DateTime.Now.Subtract(globalDateTime);
ElapsedTime(this, ts.Milliseconds);
}

I didn't compile this code but it should be pretty close.

-Joe

"pantherteeth" <pa**********@gmail.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I'm writing a little mp3 player shell type thing, and I'm trying to
figure out how to determine how long a button has been pressed.

For example, if a user clicks the left button, the song should be
decremented to the previous one. However, if the user holds the button
down for two seconds, the song would begin rewinding. Further, if the
button is pressed for five seconds, the folder will change to a
previous one.... and so on.

I can't find anywhere that says how to do this. Any suggestions?

Nov 17 '05 #2
trap the onmousedown event --- then start counting --- on mouseup event
stop counting.....

-------
Regards ,
C#, VB.NET , SQL SERVER , UML , DESIGN Patterns Interview question book
http://www.geocities.com/dotnetinterviews/
My Interview Blog
http://spaces.msn.com/members/dotnetinterviews/

Nov 17 '05 #3
Use a Windows.Forms.Timer:

button_MouseDown(...)
{
rewinding = false;
StartTimer();
}

button_MouseUp(...)
{
StopTimer();
if (rewinding)
StopRewinding();
else
PreviousTrack();
}

timer_Expired(...)
{
rewinding = true;
StartRewinding();
}

Nov 17 '05 #4

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

Similar topics

7
by: M | last post by:
i have a form which i would like to input different "action" url depending on the button that was clicked. is there a way that javascript can prefill a defined action based on the button...
1
by: John Michael | last post by:
Is it possible to detect when someone has pushed their Esc button on a form. When a form is open and someone is adding a record, if they push the esc button, the whole form gets reset to an empty...
0
by: Earl Teigrob | last post by:
This is an odd one. When I first display a thumbnail page and the user clicks one of the image links, the user goes to the correct page. If the user uses my application back button, (called...
3
by: Mel | last post by:
Hi, Is there any way I can force to change button background colour when toggle button is checked? Just like button change its background colour when mouseover in MS Visual Studio.NET. I hope I...
1
by: Ed Sutton | last post by:
<Newbie> How can I get arguments, and build a query URL, before a button is pressed? I have a text box to enter a serial number. When the search button is pressed, I wish append the serial...
4
by: OutdoorGuy | last post by:
Greetings, I have the following code in a VB.NET Windows application and was wondering if there is any way to determine whether or not the user pressed the "Cancel" button on the...
1
by: thewickedman | last post by:
Hi, I try to open new OpenOffice document (writer), But I am getting the exception FRM 40735:WHEN-BUTTON-PRESSED Trigger Raised unhandled Exception ORA - 305500 Please help me to resolve...
2
by: thesti | last post by:
hi, this might be a programming logic problem the scenario is, i have a label with imageIcon and two buttons, A and B. the label (with imageIcon) is representing the value of a randomed...
2
by: F159753 | last post by:
Hi, I have 2 text box and a "search " button. I would like to check if the text boxes are empty when the search button has been pressed. How should I do that? Regards, FF
8
by: jodleren | last post by:
Hi It is late and I am tired. I cannot remember how to check which of my buttons on the form was pressed. There are all submit's. Like echo "P=".$_POST; // and eventually using isset() ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...

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.